[quote name=‘Hoko’]Hello Snorocket thanks about your post.
But I am looking a solution for this situation:
I want create a IF condition to display a TEXT for some products in a category…
something like this:
{if $category.category_id == ‘0000’}
DISPLAY TEXT A, for all products in this category…
{else}
DISPLAY TEXT B
{/if}
Please, could you help with this?
Best Regards,
Hoko[/quote]
Snorocket gave you the proper code for making this possible, just needs to be in your categories view template (views/category/view.tpl), it’ll work just fine.
Furthermore, if you want the text to also show up on the sub-category level views, you can check {$category.parent_id} for the the main category’s id, as that’ll be set on the sub category data, so you could effectively, do something like:
{if $category.category_id == "###" || $category.parent_id == "###"} the ### being the category id.
I am looking to apply a if condition in the products page:
/customer/blocks/product_tabs/description.tpl
Can you help with this?[/quote]
On a side note about the code above, for category view data, I think the variable checks need to be on {$category_data} and not {$category}. (Sorry, just dawned on me).
Now on to the next question…
Correct, that will not work in the products view, as there is no {$category} available within the products view, as its a product, not a category view.
However, you can still achieve what you are trying to do, in that very specified template above, by utilizing the following variable checks:
showing my message, since this product IS in the wanted category
{/if}
Simply set the show_msg_in_cate_id value to the category_id that you wish to show the message with in, this code only supports a single category_id, you’d need to do it a bit differently to handle a list of them, let me know if you need multiple category_id support.
Also, this checks all the categories that are assigned to the product, not just its main, or just its additional categories, however, there are ways to check that information too, just ask!
Yeah, that’s why I said the code I provided would only work for a single category_id, but yes the code you are using does and will work, although it is not the best, I’ll reply again in a little while with a better solution, gotta try out some thoughts on the best way to allow a list.
Consider generating an array of the category id’s you want to have this work for in a post controller for categories and then making that array available to the template (Eg. $my_interesting_categories). Then: