SOLVED - Smarty Variables in PHP using $this

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
DougWare
Forum Members
Forum Members
Posts: 18
Joined: Fri Nov 07, 2008 8:50 pm

SOLVED - Smarty Variables in PHP using $this

Post 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
Last edited by DougWare on Mon Feb 16, 2009 8:15 pm, edited 1 time in total.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Smarty Variables in PHP using $this

Post by JohnnyB »

maybe this is needed?

Code: Select all

global $gCms;
$url = $gCms->variables['root_url']
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
cyberman

Re: Smarty Variables in PHP using $this

Post 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
DougWare
Forum Members
Forum Members
Posts: 18
Joined: Fri Nov 07, 2008 8:50 pm

Re: Smarty Variables in PHP using $this

Post 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
cyberman

Re: SOLVED - Smarty Variables in PHP using $this

Post 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}
Post Reply

Return to “Developers Discussion”