is there an easy way to make certain variables available in the field for: category title, category description or category meta?

Suppose we want to make our category title "{COUNT}+ Brand name products in our store" where {COUNT} holds the number of items in the category? (and it updates every time it re-indexes)

Or maybe we want to make it a little more complex and round the cound to the nearest 10fold and use that?

Is there a different nifty way? (maybe a after_html PHP regex)

on a sidenote: Will this be indexed properly? for search?

Appreciate your help

1 Answer 1


Depending on what you really want to achieve, you don't really have to make anything "available" in any complex manner. If you want to have the product count displayed as part of your category title, for example, simply update the relevant templates accordingly.

In your example, you may want to change your current templates (depending on where you want this count to be displayed) from something like this:

<div class="category-title">
    <h1><?php echo $_category->getName() ?></h1>

To something like this:

<div class="category-title">
        <?php echo $this->__('%s %s products in our store!', $_category->getProductCount(), $_category->getName()) ?>

(This would be an example in /catalog/category/view.phtml)

Which would then would look something like "59 Cool-Brand products in our store!" as the category title.

The only issue here would be that something like $_category->getProductCount() is relatively taxing on database performance, but that should not matter to much if you utilize caching.

However, alternatively you could create a new category attribute which holds the product count (or whatever property you are interested in) and calculate this using a cron job which runs once during the night or something similar. You could also add extra logic in there, such as the "round to the tenfold" or something like that. If you need these numbers to be available even quicker, an Observer hooked into the beforeSave event would be an alternative approach as well.

Will this be indexed properly? for search?

If you make it a separate category attribute, it could be used in the search without a big hit on performance. Really depends on what you have in mind exactly.

  • Really thanks for your answer. But I am sorry to say: we know how to edit template -- the question was raised because we would like to solve it in the category configuration - and hence only in the categories that we add the variable. In the suggestion above you add it to ALL categories ... (unless we build a filter). How can we make available a certain {{VAR}} like cms blocks that is parsed in the title/description
    – snh_nl
    Commented Aug 29, 2016 at 10:40
  • That would be the second part of my suggestion. You need to create a new category attribute which simply holds an integer value representing the product count (or whatever). I also gave two suggestions how to populate that: Either using an Observer or a Cron job - you could also add conditions there and limit it to certain categories. Alternatively, it could also just be a fully manual attribute. You then simply output the variable in relevant templates (and simply check if the attribute is set and if not just stick to the old behavior).
    – TiEul
    Commented Aug 29, 2016 at 10:51

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.