Jump to content
thirty bees forum
  • 0

get the current cms_category ID inside a module


Question

Posted

Hi to all,
i use to conditionally display a right column block module (html box by EmotionLoop) depending on the cms page i am with this code

{if $page_name == 'cms' && $smarty.get.id_cms}
{if in_array($id_cms, array(4,13,14,18,19,20,22))}
        {$content|escape:nofilter}
	{/if}
{/if}

This is working fine for the cms pages ...

The problem i'm digging around is that if i am on the related cms category page the right column show nothing, but i need it, so i try with this code:

{if $page_name == 'cms' && $smarty.get.id_cms_category}
  {if in_array($id_cms_category, array(2))}
        {$content|escape:nofilter}
	{/if}
{/if}

but it is not working... the module content is not showing on the right column of the cms category 2 page at all ...
attached 2 screenshoot to better explain my need .....
Someone know the reason why the module content is called correctly on a cms page and not on the related cms category pages?
Thanks in advance for your help ...

 

cms-category-page.jpg

cms--page.jpg

4 answers to this question

Recommended Posts

  • 0
Posted

Oh nice! That reminds me on my own start with coding. Keep going 😉

 

I am not sure, what the variable $page_name is. 

Maybe this is working:

{if $smarty.get.id_cms_category}
  {if in_array($id_cms_category, array(2))}
        {$content|escape:nofilter}
	{/if}
{/if}

 

I for myself would rather check CmsController and go for something like

{if isset($cms_category) && in_array($cms_category->id, array(2))}
    {$content|escape:nofilter}
{/if}

But I haven't tested it... Just wrote it 😅

 

Just when rethinking it. Maybe this is not working, since it's another column. Maybe you have to use $smarty.get.cms_category. Please confirm if some of my lines are working ^^

  • Like 1
  • 0
Posted

@wakabayashiThank you for your effort in helping me .... and for your kind words too :)  ... i'm not a developer ... just try to use my little knowledge at my best ....
So i tried both your lines of code but unfortunatly no one is working.... i tried also to play a bit with mixing the code  ... nothing happen ... :(
no cache, recompile on, also everytime deleting class_index.php ...

I can't understand why the code is working fine for cms pages and the same code adjusted for the category pages is not working at all...

if it can be of any utility, this is the url to the cms category page where the module don't show
https://www.navyonepal.it/content/category/2-navyo-nepal-discover-asia-chi-siamo
and this a relateted cms pages where the module is working fine
https://www.navyonepal.it/content/4-nostra-storia-e-le-persone

looking at the source, the variable $page_name 'cms' is the only one i can see ... both in cms category page and cms pages ... and with debug on the cms category page give warnings about 'undefined index id_cms' and 'undefined index id_cms_category ...i think here is the problem and also the solution but i'm stuck

Thanks again ... a lot!

  • 0
Posted (edited)

Thank you @yaniv14 ...that was the right solution ... great catch!!! 👍👍👍
@wakabayashiyou were very close, its me with so little code understanding not coming to the point ... thank you too! 🙏

So, if someone have a similar problem, this is the final code assembled to conditionally display my module in the right column on both cms categoriy and related cms page by given ID:

{if $smarty.get.id_cms || $smarty.get.id_cms_category}
  {if in_array($id_cms, array(4,13,14,18,19,20,22)) || in_array($smarty.get.id_cms_category, array(2))}
     {$content|escape:nofilter}
    {/if}
{/if}

 

Edited by ariom
updating with final code ...
  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...