Page 1 of 1

SOLVED - Smarty Variables in PHP using $this

Posted: Fri Feb 13, 2009 7:36 pm
by DougWare
I'm sorry, I've researched this forum for nearly two hours.  I came across a thread that was similar to what I'm trying to do, but I can't make it work.

I need two variables to be available inside the the {php} tags.  The other thread mentioned using $this->name to access the variable, but that variable is blank in php for me.  I'm pretty familiar with PHP, so I think either the variable doesn't exist or it's not making to the PHP code.

I need to do something along the lines of:

Code: Select all

{php}
$url = $this->root_url . "/script/scriptname.php?varname=" . $this->customcontent_loginname;
include($url);
{/php}
The include statement is working, but PHP is reporting that it couldn't include "/script/scriptname.php?varname=" without the variables that should have been added using $this->.

Can someone tell me if I need to enable something else or if I am referencing the variables correctly?

Thanks,
Doug

Re: Smarty Variables in PHP using $this

Posted: Sat Feb 14, 2009 3:18 am
by JohnnyB
maybe this is needed?

Code: Select all

global $gCms;
$url = $gCms->variables['root_url']

Re: Smarty Variables in PHP using $this

Posted: Sat Feb 14, 2009 6:46 am
by cyberman
root_url and customcontent_loginname are Smarty variables so you have to get it from Smarty with

Code: Select all

{php}
$root = $smarty->get_template_vars('root_url');
$ccname = $smarty->get_template_vars('customcontent_loginname');
$url = $root . "/script/scriptname.php?varname=" . $ccname;
include($url);
{/php}
http://smarty.net/manual/en/api.get.template.vars.php

Re: Smarty Variables in PHP using $this

Posted: Mon Feb 16, 2009 3:05 pm
by DougWare
I tried something similar to that, and now I've tried your code as well...

I'm getting the following error in the webserver log:

Code: Select all

Call to a member function get_template_vars() on a non-object in FileNameHiddenForPrivacyReasons
Doug
cyberman wrote: root_url and customcontent_loginname are Smarty variables so you have to get it from Smarty with

Code: Select all

{php}
$root = $smarty->get_template_vars('root_url');
$ccname = $smarty->get_template_vars('customcontent_loginname');
$url = $root . "/script/scriptname.php?varname=" . $ccname;
include($url);
{/php}
http://smarty.net/manual/en/api.get.template.vars.php

Re: SOLVED - Smarty Variables in PHP using $this

Posted: Tue Mar 03, 2009 5:50 pm
by cyberman
Have you tried this modification?

Code: Select all

{php}
global $gCms;
$root = $gCms->variables['root_url'];
$ccname = $smarty->get_template_vars('customcontent_loginname');
$url = $root . "/script/scriptname.php?varname=" . $ccname;
include($url);
{/php}