INTJP Posted February 2, 2023 Share Posted February 2, 2023 Hi there, I want to hide a specific subcategory from my category page based on its name and not based on its id. Quote <ul class="subcategories-list" > {foreach from=$subcategories item=subcategory} {if $subcategory.id_category == 36} {*I want to hide this subcategory based on its name and not based on its id*} {*this code works just fine but its uses the id, i need to use the name of the subcategory*} {else} <li> <div class="subcategory-image"> <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img"> {if !empty($subcategory.image.large.url)} <img class="replace-2x" src="{$subcategory.image.large.url}" alt="{$subcategory.name|escape:'html':'UTF-8'}" loading="lazy" width="141" height="180"/> {/if} </a> </div> <h5><a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</a></h5> {if $subcategory.description} <div class="cat_desc">{$subcategory.description|unescape:'html' nofilter}</div> {/if} </li> {/if} {/foreach} I've tried a few possibilities all of them failing : {if $subcategory.name == 'infos utiles'} {if $subcategory.cat_name == 'infos utiles'} Thanks 🙏 Link to comment Share on other sites More sharing options...
ps8modules.com Posted February 2, 2023 Share Posted February 2, 2023 Hi, {if !empty($subcategories)} {if (isset($display_subcategories) && $display_subcategories eq 1) || !isset($display_subcategories) } <div id="subcategories" class="card card-block"> <h2 class="subcategory-heading">{l s='Subcategories' d='Shop.Theme.Category'}</h2> <ul class="subcategories-list"> {foreach from=$subcategories item=subcategory} {if $subcategory.name != 'infos utiles'} <li> <div class="subcategory-image"> <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img"> {if !empty($subcategory.image.large.url)} <img class="replace-2x" src="{$subcategory.image.large.url}" alt="{$subcategory.name|escape:'html':'UTF-8'}" loading="lazy" width="141" height="180"/> {/if} </a> </div> <h5><a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</a></h5> {if $subcategory.description} <div class="cat_desc">{$subcategory.description|unescape:'html' nofilter}</div> {/if} </li> {/if} {/foreach} </ul> </div> {/if} {/if} Link to comment Share on other sites More sharing options...
INTJP Posted February 2, 2023 Author Share Posted February 2, 2023 8 hours ago, ps8moduly.cz said: Hi, {if !empty($subcategories)} {if (isset($display_subcategories) && $display_subcategories eq 1) || !isset($display_subcategories) } <div id="subcategories" class="card card-block"> <h2 class="subcategory-heading">{l s='Subcategories' d='Shop.Theme.Category'}</h2> <ul class="subcategories-list"> {foreach from=$subcategories item=subcategory} {if $subcategory.name != 'infos utiles'} <li> <div class="subcategory-image"> <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img"> {if !empty($subcategory.image.large.url)} <img class="replace-2x" src="{$subcategory.image.large.url}" alt="{$subcategory.name|escape:'html':'UTF-8'}" loading="lazy" width="141" height="180"/> {/if} </a> </div> <h5><a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</a></h5> {if $subcategory.description} <div class="cat_desc">{$subcategory.description|unescape:'html' nofilter}</div> {/if} </li> {/if} {/foreach} </ul> </div> {/if} {/if} Thank you but unfortunately this does not work... May be there a need to trigger that function from the CategoryController.php file ? I am seeing that neither calling conditional category name does not work : {if $category.name == 'mycategoryname'} YOLOLOOLO {else} HIHIHIIHH {/if} Would you have any idea how to override it to make it work ? Thanks. Link to comment Share on other sites More sharing options...
ps8modules.com Posted February 2, 2023 Share Posted February 2, 2023 (edited) Hi. I tested the TPL and it works. Can you upload your ENTIRE TPL file here? Did you delete the cache in the performance settings? Edited February 2, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
INTJP Posted February 2, 2023 Author Share Posted February 2, 2023 19 minutes ago, ps8moduly.cz said: Hi. I tested the TPL and it works. Can you upload your ENTIRE TPL file here? Thanks. Well I just pasted the whole code you gave me. So I should have the same result than you but no... I've emptied the cache via the performance page on the back office. At the moment the only way I can hide this subcategory is by using its id. Using the name does not work which is problematic because this subcategory name will be present in many others upcoming parent CategoryController.phpcategories and I'd rather not be getting into the code everytime a new one is created to insert the corresponding id. If that matters I am in a multi-stores environment. Find attached the subcategoryies.tpl file. Thanks a lot. subcategories.tpl 1 Link to comment Share on other sites More sharing options...
ps8modules.com Posted February 2, 2023 Share Posted February 2, 2023 (edited) Are you using the default template or one with elementor? Is there no space before or after the category name? Can you share the link to the eshop? Edited February 2, 2023 by ps8moduly.cz (see edit history) 1 Link to comment Share on other sites More sharing options...
INTJP Posted February 2, 2023 Author Share Posted February 2, 2023 41 minutes ago, ps8moduly.cz said: Are you using the default template or one with elementor? Is there no space before or after the category name? Can you share the link to the eshop? Thanks, your last comment helped me a lot !!! It is case sensitive ! In the BO the subcategory name was written : Infos utiles -> with a capital I while I was writing in the code : infos utiles Many thanks for your time and help 😉 1 Link to comment Share on other sites More sharing options...
ps8modules.com Posted February 2, 2023 Share Posted February 2, 2023 I gladly helped 😉 You can Like by clicking the gray heart on my posts. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now