{if} Condition for a particular category

How can i create a {if} condition for the content from particular category (products and subcategories in that main category)



I only know for a id category…

Ex:


[QUOTE]

{if $config.current_url == 'index.php?dispatch=categories.view&category_id=199 '}



DISPLAY TEXT A





{else}



DISPLAY TEXT B



{/if}





[/QUOTE]


{if $category.category_id == '199'}
DISPLAY TEXT A
{else}
DISPLAY TEXT B
{/if}

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 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.

Ok, thanks Owenad.



I try this in the products but dont work… :frowning:



I am looking to apply a if condition in the products page:

/customer/blocks/product_tabs/description.tpl



Can you help with this?

[quote name=‘Hoko’]Ok, thanks Owenad.



I try this in the products but dont work… :frowning:



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:



{assign var="show_msg_in_cate_id" value="15"}
{if (array_key_exists($show_msg_in_cate_id, $product.category_ids))}

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!



Hope this helps! :stuck_out_tongue:

Thanks Owenad!



This work!!! Now i can display som extra information product in particular categories. :wink:



My final question is how can i set various values?



{assign var=“show_msg_in_cate_id” value=“195,171” } i try this but don’t work…

I try this and work…



{assign var=“show_msg_in_cate_10” value=“10” }

{assign var=“show_msg_in_cate_20” value="20 }





{if (array_key_exists($show_msg_in_cate_10, $product.category_ids)) or

(array_key_exists($show_msg_in_cate_20, $product.category_ids))

}

TESTING



{/if}

[quote name=‘Hoko’]I try this and work…



{assign var=“show_msg_in_cate_10” value=“10” }

{assign var=“show_msg_in_cate_20” value="20 }





{if (array_key_exists($show_msg_in_cate_10, $product.category_ids)) or

(array_key_exists($show_msg_in_cate_20, $product.category_ids))

}

TESTING



{/if}[/quote]



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:

```php

{if $my_interesting_categories|array_intersect:$product.category_ids }

showing my message, since this product IS in the wanted category


{/if}
```

hello everyone,

i want to fetch subcategories by category id
is it possible??

thanks

hello everyone,

i want to fetch subcategories by category id
is it possible??

thanks

Try

PHP:

$subcats = fn_get_subcategories($category_id);
fn_print_r($subcats);

TPL:

{$subcats = $category_id|fn_get_subcategories}
{$subcats|fn_print_r}

hello,

i want quick view pop-up on product image and product name
is there any solution??

thanks

i want quick view pop-up on product image and product name

is there any solution??

What template do you mean?