Jump to content

[SOLVED] variables not accessible in left column (header.tpl)-$category class not available


sixthmind

Recommended Posts

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?

Link to comment
Share on other sites

thanks Elpatron for your reply. I am already using {debug}. That's how I find all the variables. But the question is how to make certain variables like $category, which is class, available also in header.tpl and blockcms.tpl and not only available in cms.tpl.

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.

Link to comment
Share on other sites

Ok, I understand class $category is not included in header.tpl and blockcms.tpl. I still need to figure out how to include it, so I can then use its variables.

I wonder if I was meant to put this code in header.php or somewhere else:

 

include_once("../classes/Category.php");
include_once("../classes/CMSCategory.php");

Link to comment
Share on other sites

Ok, may I ask why ProductController.php? Development guide says that this controller is used by product.php to get a product. $category is currently available in cms.tpl, so shouldn't I be looking at CMSController for something in there? well, i found this code in ProductController.php:

/* Category */
               $category = false;
               if (isset($_SERVER['HTTP_REFERER']) AND preg_match('!^(.*)\/([0-9]+)\-(.*[^\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) AND !strstr($_SERVER['HTTP_REFERER'], '.html'))
               {
                   if (isset($regs[2]) AND is_numeric($regs[2]))
                   {
                       if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[2])))))
                           $category = new Category((int)($regs[2]), (int)(self::$cookie->id_lang));
                   }
                   elseif (isset($regs[5]) AND is_numeric($regs[5]))
                   {
                       if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[5])))))
                           $category = new Category((int)($regs[5]), (int)(self::$cookie->id_lang));
                   }
               }
               if (!$category)
                   $category = new Category($this->product->id_category_default, (int)(self::$cookie->id_lang));

               if (isset($category) AND Validate::isLoadedObject($category))
               {
                   self::$smarty->assign(array(
                       'path' => Tools::getPath((int)$category->id, $this->product->name, true),
                       'category' => $category,
                       'subCategories' => $category->getSubCategories((int)self::$cookie->id_lang, true),
                       'id_category_current' => (int)$category->id,
                       'id_category_parent' => (int)$category->id_parent,
                       'return_category_name' => Tools::safeOutput($category->name)
                   ));
               }
               else
                   self::$smarty->assign('path', Tools::getPath((int)$this->product->id_category_default, $this->product->name));

               self::$smarty->assign('return_link', (isset($category->id) AND $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');

 

So would I have to create a copy of controller in override folder and put something in there so that certain classes would be available in other template files as well?

Link to comment
Share on other sites

  • 4 weeks later...

Hi sixthmind,

 

Did you find a solution to this? I am having basically the same problem since I don't want to display the left column if the products belong to a certain category. However, smarty doesn't know about the $category variable at the moment it prints the left column. Did you solve it? And in that case would you care to share your solution?

 

Thank you very much.

Link to comment
Share on other sites

On my part I solved this by using the $name variable instead of the $category (the category I am interested in contains only one product which is the one that needs a completely different layout).

 

I tried to implement the code above from ProductController.php into FrontController.php but with no success. Couldn't understand how to modify the call to idIsOnCategoryId.

Link to comment
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
×
×
  • Create New...