Jump to content

Seperate Category.tpl Page


clanger

Recommended Posts

Hello Everyone,

First time poster and I'm not that great with PHP. I know bits and pieces and can usually figure code out by looking it over. What I am trying to accomplish is have a category page that has a different theme than the rest of them. I have created a category2.php and CategoryController2.php as well as category2.tpl

 

When calling on www.xxxxx.com/category2.php?id_category=1 for example, I get redirected to www.xxxxx.com/category.php which is displaying error:

 

There is 1 error :

 

  1. Missing category ID

Any advice?

 

Thanks in advance.

Link to comment
Share on other sites

This is a bulkier way of doing it, but this is what I do in a situation like that. This is in pseudo code also

 

if category ==12

new category html

else

regular category html

/if

 

I just append the category.tpl and use an if statement in it to decide what to show. So then everything is in one file and you are not modifying anything more than the template. A little more code overhead on your server, but it is really not an issue.

Link to comment
Share on other sites

I am assuming that something would have to be added to this section of the categorycontroller?

 

 

 

 

public function displayContent()
{
 parent::displayContent();
 self::$smarty->assign('categoryNameComplement', '');
 self::$smarty->display(_PS_THEME_DIR_.'category.tpl');
}

 

Any help at all is GREATLY appreciated.

Link to comment
Share on other sites

I just need to have a seperate category.TPL file so I can theme it differently. It won't have the left colums, right column, etc. Basically just have the products and some text aroud the page that will be updated from time to time.

Link to comment
Share on other sites

  • 1 month later...

I am currently trying to get one category to load a different category.tpl file based on the category id so I have edited CategoryController.php and changed

 

public function displayContent()
{
 parent::displayContent();
self::$smarty->display(_PS_THEME_DIR_.'category.tpl');
}
}

 

to

 

public function displayContent()
{
 parent::displayContent();

 if ($_GET['id_category'])
   $category = $_GET['id_category'];
else if ($_GET['id_product'])
{
   $product = new Product($_GET['id_product']);   
   $category = $product->id_category_default;
}
self::$smarty->assign('category', $category);
 if(($category) == '2')
 self::$smarty->display(_PS_THEME_DIR_.'category2.tpl');
 else
 self::$smarty->display(_PS_THEME_DIR_.'category.tpl');
}
}

But now it appears that neither category.tpl nor category2.tpl will load, every thing else is fine though.

 

As for having a category page without the left column and right colum, you would need to load a different header.tpl for the left and a different footer.tpl for the right, I have managed to get that to work using basically the code above in frontcontroller.php

Link to comment
Share on other sites

First, *NEVER* edit core files. You should not have to, you can use class overrides for this purpose (look at "/overrides").

 

Second, you have no guarantee that the category ID is being passed by GET nor should you have to worry about that. It will be set properly when CategoryController::process() is called. So instead use the category object itself to test against:

 

public function displayContent()
{
 parent::displayContent();
 self::$smarty->assign('categoryNameComplement', '');
 if($this->category->id_category=1234)
 {
  self::$smarty->display(_PS_THEME_DIR_.'category1234.tpl');
 }
 else
 {
  self::$smarty->display(_PS_THEME_DIR_.'category.tpl');
 }
}

 

Cheers

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