red sun Posted May 19, 2013 Share Posted May 19, 2013 In an effort to solve an issue with the newsletter subscription form not providing a success message I thought a quick solution would be to look for the "subscribed" variable in the url and use php to echo a success message (I know the recommended approach is to create a plug-in but that is beyond my abilities). I followed the instructions in the CubeCart support files for enabling PHP in templates and added the following code in controllers/controller.index.inc.php: $GLOBALS['smarty']->allow_php_tag = true; The documentation states 1. For front end skins server from the /skins folder please open the controllers/controller.index.inc.php file However there is no "controllers" directory under "skins", so i modified "controllers/controller.index.inc.php". I then added the smarty php tags as per http://www.smarty.net/docsv2/en/language.function.php.tpl However when I try to add any code, or even just empty {php} {/php} tags the page fails to load. Has this feature been removed form the latest version of CubeCart or have I missed someting really basic? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 19, 2013 Share Posted May 19, 2013 Those are the docs for Smarty v2 -- CubeCart 5 is using Smarty v3.1.x and the {php} tags are no longer valid. See: http://www.smarty.net/docs/en/language.function.php.tpl Quote Link to comment Share on other sites More sharing options...
red sun Posted May 19, 2013 Author Share Posted May 19, 2013 Hi bsmither - thanks for letting me know. I take it there's no way to put your own php in the templates now. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 19, 2013 Share Posted May 19, 2013 According to the Smarty docs, you can switch out the class instantiation from: $GLOBALS['smarty'] = new Smarty(); to $GLOBALS['smarty'] = new SmartyBC(); in the /controllers/controller.index.inc.php file. (SmartyBC - backward compatibility - extends from Smarty.) Quote Link to comment Share on other sites More sharing options...
red sun Posted May 19, 2013 Author Share Posted May 19, 2013 Hi there - I tried that and also updated the path in autoloader.class.php to the following without any success. require_once CC_INCLUDES_DIR.'lib'.CC_DS.'smarty'.CC_DS.'SmartyBC.class.php'; Your reply to my other post regarding problems with the newsletter form not showing a response has helped greatly, so I have no need to add custom php to the templates at this time. Many thanks for your help so far. I may re-open this topic if I hit any future problems where custom php would provide a quick fix... Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 19, 2013 Share Posted May 19, 2013 Might also have needed to change the statement above: if ($class == 'SmartyBC') { Or, maybe, we could have not changed the controller file, not changed the if statement, and just relied on the changed require_once statement??? Quote Link to comment Share on other sites More sharing options...
red sun Posted May 19, 2013 Author Share Posted May 19, 2013 A combination of all three of your suggestions did the trick. In controllers/controller.index.inc.php change $GLOBALS['smarty'] = new Smarty(); to $GLOBALS['smarty'] = new SmartyBC(); in classes/autoloader.class.php change if ($class == 'Smarty') { require_once CC_INCLUDES_DIR.'lib'.CC_DS.'smarty'.CC_DS.'Smarty.class.php'; return true; } to if ($class == 'SmartyBC') { require_once CC_INCLUDES_DIR.'lib'.CC_DS.'smarty'.CC_DS.'SmartyBC.class.php'; return true; } Finally, I popped the following code into the template file box.newsletter.php {php} echo (isset($_GET['subscribed']))?'<p class="confirmation">Thank you for subscribing</p>':''; {/php} Many thanks bsmither - another problem solved !!! Quote Link to comment Share on other sites More sharing options...
red sun Posted May 19, 2013 Author Share Posted May 19, 2013 Sorry - was a bit hasty there - carrying out the actions in the preceeding post knackers the admin area. I'm assuming it can't find its template files... Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 19, 2013 Share Posted May 19, 2013 This one Smarty statement should do the same as the {php} attempt: {if !empty($smarty.get.subscribed)}<p class="confirmation">Thank you for subscribing</p>{/if} See: http://www.smarty.net/docs/en/language.variables.smarty.tpl#language.variables.smarty.request Knackering the admin area... maybe. But there is a separate controller file for the admin. Quote Link to comment Share on other sites More sharing options...
red sun Posted May 19, 2013 Author Share Posted May 19, 2013 To get the admin area working change the following in controllers/controller.admin.pre_session.inc.php $GLOBALS['smarty'] = new Smarty(); to$GLOBALS['smarty'] = new SmartyBC(); Quote Link to comment Share on other sites More sharing options...
red sun Posted May 19, 2013 Author Share Posted May 19, 2013 Thank you - a much simpler and more appropriate way of acheiving the outcome rather than turning on PHP and altering core files - thanks again... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.