Jump to content

Get CMS ID in template


Recommended Posts

I have the following header navigation bar:

<ul id="header_links">
<li><a href="{$link->getPageLink('index.php')}"{if $page_name == 'index'} class="active"{/if}><span>{l s='home' mod='tmheaderlinks'}</span></a></li>
<li><a href="{$link->getPageLink('prices-drop.php')}"{if $page_name == 'prices-drop'} class="active"{/if}><span>{l s='specials' mod='tmheaderlinks'}</span></a></li>
<li><a href="{$link->getCMSLink('1')}"{if $page_name == '?'} class="active"{/if}><span>CMS site 2</span></a></li>
<li><a href="{$link->getCMSLink('2')}"{if $page_name == '?'} class="active"{/if}><span>CMS site 2</span></a></li>
<li><a href="{$link->getPageLink('sitemap.php')}"{if $page_name == 'sitemap'} class="active"{/if}><span>{l s='sitemap' mod='tmheaderlinks'}</span></a></li>
<li><a href="{$link->getPageLink('contact-form.php')}"{if $page_name == 'contact-form'} class="active"{/if}><span>{l s='contact' mod='tmheaderlinks'}</span></a></li>
</ul>

 

My problem is to detect the current CMS page, to add a class to it. {$page_name} only returns "cms" on all CMS pages. Is there any variable to detect the ID of the CMS-page?

I have googled it, but I can't find it. Any help please?

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hello,

$cms->id returns nothing for me...

I try this code to simply add a "selected" class :

<li><a href="{$cms_page.link}" {if isset($currentCategoryId) && ($cms_page.id_cms == $currentCategoryId)}class="selected"{/if} title="{$cms_page.meta_title|escape:html:'UTF-8'}">{$cms.id}-{$cms_page.id_cms}-{$cms_page.meta_title|escape:html:'UTF-8'}</a></li>

Where "{$cms.id}-{$cms_page.id_cms}-" are my witness.

 

"

$cms_page.id_cms

" returns the good ID for each link, but I don't finbd how to get the "current-cms-page-id".

 

Any idea ?

Share this post


Link to post
Share on other sites

Hello,

$cms->id returns nothing for me...

I try this code to simply add a "selected" class :

<li><a href="{$cms_page.link}" {if isset($currentCategoryId) && ($cms_page.id_cms == $currentCategoryId)}class="selected"{/if} title="{$cms_page.meta_title|escape:html:'UTF-8'}">{$cms.id}-{$cms_page.id_cms}-{$cms_page.meta_title|escape:html:'UTF-8'}</a></li>

Where "{$cms.id}-{$cms_page.id_cms}-" are my witness.

 

"

$cms_page.id_cms

" returns the good ID for each link, but I don't finbd how to get the "current-cms-page-id".

 

Any idea ?

 

Hello,

 

{$cms.id} is completely different to {$cms->id}

 

So try using {$cms->id} as written in our previous post.

  • Like 1

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 7 months later...
  • 6 months later...

try this one {$smarty.get.id_cms} ;)

Thanks so much for this !

Actually, i'm working on the template blockcms.tpl (Prestashop v1.4.10) and what is strange is that the {debug} returns values for $cms but not for $cms_title (used in blockcms.tpl). Other strange thing, both {$cms->id} or {$cms.id} don't work for me.

 

Only {$smarty.get.id_cms} works for me !

 

Thanks very much ! :D

Share this post


Link to post
Share on other sites

(Prestashop v1.4.10)

and what is strange is that the {debug} returns values smarty.get.id_cms} works for me !

 

Thanks very much ! :D

 

thanks for that, im convinced that it will be really helpful for other forum members :)

regards

Share this post


Link to post
Share on other sites

  • 1 year later...
Prestashop 1.4.4.1 
I used this: 

 

<li><a href="{$link->getPageLink('cms.php?id_cms=1')}"{if $smarty.get.id_cms == '1'} class="active"{/if}>{l s='cms1' mod='tmheaderlinks'}</a></li>

 

 
works

Share this post


Link to post
Share on other sites

  • 2 months later...

This also works

 

// File: product.tpl
// Line: 225 (depends on desired location)
// This code will display a translatable link that will display a fancybox popup.
// The content for this fancybox is a CMS page that is displayed as content-only.
// Change the CMS ID with the correct cms page.
// Change the width&height of the fancybox with javascript and the size of the cms page.
 
<!-- 108Bits -->
    {if !$logged}
     <p><a href="{$link->getCMSLink('8')}?content_only=1" class="iframe" rel="nofollow">
     {l s='Shipping Terms'}</a></p>
    {/if}
<!-- END 108Bits -->
 
// Add this at the end of the file (after {/if} )
<script type="text/javascript">
    $('a.iframe').fancybox({
        'type' : 'iframe',
        'width':500,
        'height':900
    });
</script>

Share this post


Link to post
Share on other sites

  • 1 month later...

 

Prestashop 1.4.4.1 
I used this: 

 

 
works

 

 

Prestahop 1.6.0.9

 

No more working for me.

 

I have this error :

 

 

NOTICE: UNDEFINED INDEX: ID_CMS IN/THEME-FOLDER/TOOLS/SMARTY/SYSPLUGINS/SMARTY_INTERNAL_TEMPLATEBASE.PHP(157) : EVAL()'D CODE ON LINE 36

Edited by Klemart3D (see edit history)

Share this post


Link to post
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More