Jump to content

Template Override Not Working


Recommended Posts

I'm using PrestaShop 1.6.0.9.

 

I need to override the default category layout for specific category IDs and have created an override CategoryController.php to do this. I need to change the default_subcat image to another of a different size that I have set up.

 

For specific category IDs I am executing

 

$this->setTemplate(_PS_THEME_DIR_.'category-type2.tpl');

 

I believe that this code is being executed as if I put "print $this->category->id;" in the same block, the category IDs of those I would like to override is shown at the top of the page.

 

However, it seems that the default category template is being used and that the override is not effective. I cannot see any errors or other messages, just the category ID being displayed for the specific categories I need to override.

 

Why might this be?

 

I have cleared the cache several times.

 

Any help would be much appreciated!

 

Thanks,

 

Alan

Link to comment
Share on other sites

Nemo1,

 

In /override/controllers/front I created CategoryController.php and in there added:

class CategoryController extends CategoryControllerCore {

    // array with the selected categories
    private $customCategories = array(1051, 1052, 1053);

    public function init() {
        parent::init();
        if (in_array($this->category->id, $this->customCategories)) {
          print $this->category->id; 
          $this->setTemplate(_PS_THEME_DIR_.'category-type1.tpl');
        }
    }
}
I know that the logic goes through the block of code that sets the category template as the category ID is printed at the top of the rendered page.
 
What I don't know if when this code is executed in relation to parent - is it before, instead of, or after?
 
I've been able to get the template switch to take place by adding the code to /controllers/front/CategoryController.php, but would rather not do this. 
 
Thanks for the link to the page discussing overrides - I'll have a look at this.
 
Alan
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...