We strongly recommend using CubeCart’s hooks and plugin system instead of embedding PHP directly in template files. Plugins keep your customisations modular, upgrade-safe, and easy to maintain.
The Recommended Approach: Plugins
Create a plugin that performs your PHP logic and passes the result to the template:
// In your plugin's hook file:
$GLOBALS['smarty']->assign('MY_CUSTOM_DATA', $myValue);
Then in your template:
{$MY_CUSTOM_DATA}
See our guides on creating plugins with the hooks system and creating custom front-end pages.
If You Must Use PHP in Templates
Smarty does provide a {php} tag, but it is deprecated and discouraged. Consult the Smarty documentation if absolutely necessary. Be aware that this approach:
- May break during CubeCart or Smarty upgrades
- Makes your templates harder to maintain
- Can introduce security vulnerabilities if not done carefully