Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7649765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:03:19+00:00 2026-05-31T11:03:19+00:00

I am currently learning template variables and trying to understand how they work and

  • 0

I am currently learning template variables and trying to understand how they work and what they mean.
I’ve done a test on {$category->id_cms_category}, which I put in cms.tpl and I get a result 9, but when I put this in header.tpl or blockcms.tpl (left column), there is no results, it’s blank.

Can somebody please explain how this works and how I can get the same result in different .tpl file?
I think the question is really how to assign $category class to for example header.tpl. Is it something to do with controllers?
Why can’t I use certain variables everywhere? How does this work? I would be very happy if somebody explain this.
I am also still learning smarty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:03:20+00:00Added an answer on May 31, 2026 at 11:03 am

    Unfortunately you’re hitting a common problem with smarty, and particularly how it’s implemented within Prestashop.

    Smarty variables are very much limited in scope within Prestashop and their scope is determined by which point the portion of code they are assigned in is run. In the case of {$category->id_cms_category} it is assigned within the CMSController at the point in which the main content (important stuff in the middle) is rendered, and so will be available within cms.tpl as you have demonstrated.

    The reason it isn’t available in the left column or in the header is due to the order in which each of these sections are rendered. This will be:

    a) Header (top of page rather than the html header block specifically), then
    b) Left Column, then
    c) “Main” Content, then
    d) Right Column, then
    e) Footer

    You should find that if you were to reference it in the right column or the footer of the page, then magically it will be available to you (on CMS pages only of course as we’re relying on the CMSController being run and assigning it a value).

    If you need to reference things like the cms category within the header of the page (maybe to set a highlight on horizontal navigation) then you’re going to need to fetch the value and assign it to smarty yourself. You can do this in one of two ways:

    1) Write a module which is hooked into the header and assign your variable there
    2) Override the FrontController class and assign the smarty variable there (e.g. in the init function)

    An example of 2) which you could try is to create a file /override/classes/FrontController.php containing:

    <?php
    class FrontController extends FrontControllerCore
    {
      function init() {
        parent::init();
        $id_cms_category = (int)Tools::getValue('id_cms_category');
        $id_cms_page = (int)Tools::getValue('id_cms');
        self::$smarty->assign(array(
                                    'my_cms_category_id' => $id_cms_category,
                                    'my_cms_page_id' => $id_cms_page
                                    )
                              );
      }
    }
    

    The above should allow you to display {my_cms_category_id} and {my_cms_page_id} anywhere in your theme (because we’re setting the smarty variables before everything else is rendered). For a non-cms page they should both be 0, my_cms_category_id should be set non-zero on cms category pages, and {my_cms_page_id} should be non-zero when on a specific cms page.

    Hope this goes some way to making it a little clearer!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently learning Haskell. I am trying to write a function which given
I'm currently learning Haskell, Which language (F# or Haskell) do you prefer for programming
Currently learning Spring MVC with Spring 3, I'm trying to find the correct way
I currently learning about scrum and want to learn from experienced professionals in the
im currently learning python (in the very begining), so I still have some doubts
im currently learning stacks in java and have a quick question. what will the
So I am currently learning C++ and decided to make a program that tests
I'm currently learning the APIs related to Intel's parallelization libraries such as TBB, MKL
I'm currently learning to develop for the .net compact framework using c# in VS2008
I'm currently learning Ruby and RoR and I stumbled across this declaration: link_to_remote(name, options

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.