In my layered navigation I want to be able to theme the content for each attribute differently. I have done this by creating my own version of app\design\frontend\base\default\template\catalog\layer\view.phtml and adding a class with the attribute name (which I can then target with css) by modifying this line from

<dd><?php echo $_filter->getHtml() ?></dd>


<dd class="<?php echo $this->__($_filter->attribute_model->attribute_code) ?>"><?php echo $_filter->getHtml() ?></dd>

This works fine but I noticed I was getting the following error in my log at this line:

ERR (3): Notice: Trying to get property of non-object in app/design/frontend/mytheme/default/template/catalog/layer/view.phtml on line 53

Fortunately, it's invisible on the front end and I'd like to eliminate it.

It dawned on me that this happens when the layered navigation is in a category tree and so there are no active attributes. I have tried to test if an attribute exists using the likes of is_object but nothing's worked and it's exhausted my admittedly limited PHP skills.

Can anyone suggest a way that works?

4 Answers 4


You should die(var_dump($_filter)) var to see what is inside. After that you will be able to use the property of the object you need to achieve what you want.


What that error is saying is $_filter is not an object at a certain time o.o so what I would do is see what $_filter is returning when that error hits. You can do this with an log (There should be a weird occurrence when the error).

Before you call echo $this->__($_filter... log $_filter with this Mage::log(var_dump($_filter)). If its not an object then you should get a string or a number or an empty var o.o.

  • What does o.o mean?
    – mbalparda
    Commented Feb 6, 2015 at 13:31
  • its a face. :l i forget to take those out.
    – Aedonis
    Commented Feb 7, 2015 at 0:59

I believe your is_object() approach is correct here, you most likely were just using it incorrectly.

My guess is you had something similar to this:

<?php if (is_object($_filter)): ?> ... <?php endif ?>

I would try revising it to this:

<?php if (is_object($_filter->attribute_model)): ?> ... <?php endif ?>


Thanks for your suggestions which helped me work out what I was doing wrong. Fundamentally it was my poor php. I now have the following which means the error no longer occurs.

 <dd<?php if (!is_null($_filter->attribute_model)) {echo ' class="' . $this->__($_filter->attribute_model->attribute_code) . '" ';} ?>><?php echo $_filter->getHtml() ?></dd>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.