CMS 2: need help $smarty in UDT

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
Locked
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

CMS 2: need help $smarty in UDT

Post by jsmonzani »

Hello
I'm trying to upgrade my websites to CMS v.2 and I'm running into problems with $smarty in UDT.

Basically, I know how to get / set data in $smarty and in $gCms in v.1 but I fail to map my knowledge to v.2. I've read the Introduction to Writing Modules for CMS Made Simple as well as the new doc on writing UDT but couldn't find answers here.

I understand that there's a new concept of "local" rather than "global" $smarty vars but I'm unsure how to handle that.

Basically, I'm trying to define smarty variables in a UDT, then read it in another UDT.

Code: Select all

// WRITE DATA in UDT #1
global $smarty;
$smarty->assign('weblang', $mydata);

// READ DATA  in UDT #2
global $smarty;
......... $smarty->get_template_vars('weblang') ......
but this doesn't seem to work, as if $smarty scopes where different.

I understand that I should remove global $smarty; but how to make this work? How to make things global? Maybe I should use this new " $smarty->fetch(...)" but I don't know how to find documentation on it. Could someone please help?

Now for something different, am I doing this correctly?

Code: Select all

// for v.1
$gCms = cmsms();

// for v.2
$gCms = CmsApp::get_instance();
My final code actually tries to grab content blocks

Code: Select all

$c_ =$currentContent->GetPropertyValue('_content_' . $smarty->get_template_vars('weblang')); 
chandra

Re: CMS 2: need help $smarty in UDT

Post by chandra »

Please try

Code: Select all

$smarty->assignGlobal('weblang', $mydata);
http://forum.cmsmadesimple.org/viewtopi ... 22#p324122

By the way ... you should try to use Smarty3 style

Code: Select all

$smarty->getTemplateVars('weblang');
instead

Code: Select all

$smarty->get_template_vars('weblang');
http://www.smarty.net/docs/en/api.get.template.vars.tpl
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: CMS 2: need help $smarty in UDT

Post by Jeff »

IMO, anything needed inside the UDT should be passed in as a param (think of an UDT as a function).

{myUDT myvar=$var}

then in the UDT

$somevar = $param['myvar'];
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

Re: CMS 2: need help $smarty in UDT [SOLVED]

Post by jsmonzani »

Thank you very much for your replies!

All is working now, and I can confirm that $gCms assignment is working properly too.

Thanks Jeff for your suggestion, I do agree with you. There's actually a reason for using global smarty variables in my application.

(Just looking for how to mark this topic as solver now :D )
Locked

Return to “Developers Discussion”