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?

Link to comment
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 ?

Link to comment
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
Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • 1 year later...
  • 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>
Link to comment
Share on other sites

  • 1 month later...

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