Page 1 of 1
Using PHP scripts
Posted: Sun Apr 16, 2006 8:27 am
by pdedecker
Is it possible to insert PHP code in a page? (not just predefined PHP-code, I want to able to edit the code right from the Page editor)
Re: Using PHP scripts
Posted: Sun Apr 16, 2006 1:55 pm
by calguy1000
you can use {literal}{/literal}
or write them once in a user defined tag
Re: Using PHP scripts
Posted: Wed May 03, 2006 3:49 am
by mikemcvey
Hey, just a note.. the {literal} tags didn't work for me.
Just printed the contents in html code tag.
Best to just make a new tag anyway
Re: Using PHP scripts
Posted: Wed May 03, 2006 9:52 am
by Ted
You CAN use {php}echo "blah";{/php} tags, but you have to turn the option on in config.php. I feel it's a little too unsafe to just leave wide open.
Re: Using PHP scripts
Posted: Mon May 08, 2006 9:39 pm
by rcp
I've used {php} code snippets several times and they worked OK but I think I just found a bug in the latest CMSMS beta!
I have a page with a random background -
The preview in the admin works as expected but accessing the page outside admin doesn't, the {php} tags are ignored and this shows up:
Any idea why this happens? Thanks in advance!
(yup, have "$config['use_smarty_php_tags'] = true;" in config.php)
Re: Using PHP scripts
Posted: Mon May 08, 2006 9:45 pm
by Ted
Is that in the page or the template?
Thanks!
Re: Using PHP scripts
Posted: Mon May 08, 2006 10:21 pm
by rcp
Ted wrote:
Is that in the page or the template?
Template.
Re: Using PHP scripts
Posted: Mon May 08, 2006 10:50 pm
by Ted
Interesting. I see it being a problem with the config file in content not getting parsed...
Open up lib/content.functions.php. Look for
Code: Select all
function content_get_template($tpl_name, &$tpl_source, &$smarty_obj)
{
global $gCms;
$pageinfo = &$gCms->variables['pageinfo'];
and add this line to make it:
Code: Select all
function content_get_template($tpl_name, &$tpl_source, &$smarty_obj)
{
global $gCms;
$config =& $gCms->GetConfig();
$pageinfo = &$gCms->variables['pageinfo'];
Then clear the cache and see if it helps any. Thanks!
Re: Using PHP scripts
Posted: Mon May 08, 2006 11:06 pm
by rcp
Wow, that solved the problem, thanks a lot.
1 less bug to go

Re: Using PHP scripts
Posted: Mon May 08, 2006 11:29 pm
by Ted
Excellent. Thanks. That'll be in the next release.
Re: Using PHP scripts
Posted: Tue May 09, 2006 2:24 pm
by rcp
Seems like there are more places to apply that patch:
in a template - {php} $variable='value'; {/php}
in a page (that uses the template) - {php} echo $variable; {/php} - doesn't output anything. Tried putting global $variable everywhere but doesn't work.
Again, all works fine in preview in the admin tool.
Re: Using PHP scripts
Posted: Tue May 09, 2006 4:10 pm
by Ted
Actually, that isn't really a fixable thing. templates and page aren't in the same scope, and you can't count on the order of which they'll get processed. Chances are that declaring as global MIGHT work, but I wouldn't count on it.
A better bet would be to use smarty to do this.
{capture assign='variable'}value{/capture}
and then
{$smarty.capture.variable}
Though, I would some testing to make sure they're always used processsd in the same order.