Using PHP scripts
Using PHP scripts
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)
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Using PHP scripts
you can use {literal}{/literal}
or write them once in a user defined tag
or write them once in a user defined tag
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Using PHP scripts
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
Just printed the contents in html code tag.
Best to just make a new tag anyway
Re: Using PHP scripts
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
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)
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
Interesting. I see it being a problem with the config file in content not getting parsed...
Open up lib/content.functions.php. Look for
and add this line to make it:
Then clear the cache and see if it helps any. Thanks!
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'];
Code: Select all
function content_get_template($tpl_name, &$tpl_source, &$smarty_obj)
{
global $gCms;
$config =& $gCms->GetConfig();
$pageinfo = &$gCms->variables['pageinfo'];
Re: Using PHP scripts
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.
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
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.
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.