Switching templates

Changing configuration values when template changes

The process of changing templates can be done using the Template Selection screen under Admin > Tools.

But what if the templates you are switching between expect different configuration values? It’s tedious to do these by hand, especially if you’re switching back and forth doing tests.

That’s why Zen Cart 1.5.8a introduces a new feature called template_init. Place a file called template_init.php in the includes/templates/YOURTEMPLATE folder. It will run when the template is set to YOURTEMPLATE.

For example, here’s a template init that turns off CSS buttons when this template is selected:

<?php
// Settings for Older Template
$db->Execute("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='No' WHERE configuration_key  = 'IMAGE_USE_CSS_BUTTONS'");

Any configuration variable can be set in the same way.

If you can’t recall the name of a particular variable, remember you can look it up on the All Configuration Settings page.

If you are using an older Zen Cart version and want this feature, you can merge this PR into your copy of admin/template_select.php.




Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified November 19, 2022 by Scott C Wilson (cd5ef02d).