Page 1 of 1

Smarty and the {php} tag triggers multiple errors [solved]

Posted: Sun Feb 17, 2008 2:31 am
by jamesbisset
I've inherited a CMS MS site with a template which includes raw php inside Smarty {php} 'php and mysql stuff' {/php] tags. The page in question works fine at it's current install location. But a fresh install of CMS MS (and appropriate modules) with an imported db at the new location falls over.

Specifically, Smarty seems to be trying to parse every '{' inside the {php} {/php} tags.

EG: {php} if($foo = 'bar') {while etc... {/php} causes a Smarty error "syntax error: unrecognized tag 'while' (Smarty_Compiler.class.php, line 590)".

Has the previous admin done some cunning low-level tweaking, or is this some obscure aspect of server file permissions or wot?

Anyone got any clues?

Additional info: both servers are running PHP 5. CMS MS on previous server 1.0.6. The errors on the new server occur with both 1.0.6 and upgraded 1.2.3. No shell access, so uploads are all done with FTP.

Re: Smarty and the {php} tag triggers multiple errors

Posted: Sun Feb 17, 2008 3:48 am
by nivekiam
Have you modified config.php to use {php} tags in smarty?

Set this to true:
$config['use_smarty_php_tags'] = true;

Be aware that this could be dangerous to allow if you a) don't trust your users and b) allow other people than yourself to edit pages.  It allows anyone who can create/edit content to insert any php code into the page and it's executed.

You may want to look at using a UDT (User Defined Tag) instead:
http://wiki.cmsmadesimple.org/index.php ... fined_Tags

I don't know what PHP code they've written, but you might be able to take that php code and pop it into a UDT and call the UDT from the page.  That would be much safer than enabling the use of raw php code inside Smarty tags.

Re: Smarty and the {php} tag triggers multiple errors

Posted: Sun Feb 17, 2008 4:15 am
by jamesbisset
nivekiam wrote: Have you modified config.php to use {php} tags in smarty?

Set this to true:
$config['use_smarty_php_tags'] = true;
Aha! Thanks for that. Now it works! Thanks too for the warning about the security issues enabling this config. It's not a worry for the moment, as every other user of the site is producing content only and wouldn't know a Smarty Tag if it bit them in the ---, but it's something to bear in mind.

My guess is that the original developer planned to build a module to handle all the custom PHP, because ModuleMaker was installed too, but the company went bust before they got round to it.

Thanks :)