HowTo: Theme switching
In tradition with my current just-in-time documentation a quick note about theme switching.
As explained previously, the theme id is taken from zen-cart. In order to be able to that, a ZenMagick installation patch exists, that will create dummy files to make zen-cart believe that those themes exist as zen-cart templates.
Theme switching is a feature in ZenMagick that allows to programmatically change the theme for the current request. The ideal place for that is any local.php that gets loaded, so either the global local.php file in zenmagick, or the one in the extra directory of the currently configured theme.
The code itself is a no-brainer:
<br /> if ('contact_us' == $zm_request->getPageName()) {<br /> $zm_runtime->setThemeId('default');<br /> }<br />
This, for example, will switch to the default theme if the contact us form is displayed.
It is possible to have multiple switched per request (in the above example, the default theme could decide to switch to yet another theme under certain conditions..). Obviously, performance will suffer from too many switches.
A related feature is theme inheritance. This means that, like in zen-cart, template files/resources that can’t be found in the current theme will be looked up in the default theme. This may be disabled by setting ‘isEnableThemeDefaults‘ to false.
If disabled, templates will execute a little bit faster. However, it requires to have a “complete” theme. Depending on the complexity of your template changes this might mean that a lot of files need to be copied without any change. One potential downside is that files may need to updated as new ZenMagick releases require modifications to those files.
