• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: CMS 2: need help $smarty in UDT
PostPosted: Tue Jun 28, 2016 1:59 pm 
Offline
Forum Members
Forum Members

Joined: Mon Apr 03, 2006 10:58 am
Posts: 54
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:
// 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:
// for v.1
$gCms = cmsms();

// for v.2
$gCms = CmsApp::get_instance();


My final code actually tries to grab content blocks
Code:
$c_ =$currentContent->GetPropertyValue('_content_' . $smarty->get_template_vars('weblang'));


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: CMS 2: need help $smarty in UDT
PostPosted: Tue Jun 28, 2016 9:44 pm 
Offline
Power Poster
Power Poster

Joined: Sat May 05, 2012 7:29 pm
Posts: 404
Location: India
Please try

Code:
$smarty->assignGlobal('weblang', $mydata);


viewtopic.php?t=73550&p=324122#p324122

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

Code:
$smarty->getTemplateVars('weblang');


instead

Code:
$smarty->get_template_vars('weblang');


http://www.smarty.net/docs/en/api.get.template.vars.tpl


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: CMS 2: need help $smarty in UDT
PostPosted: Wed Jun 29, 2016 5:36 am 
Offline
Power Poster
Power Poster

Joined: Mon Jan 21, 2008 5:51 pm
Posts: 961
Location: MI
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'];


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: CMS 2: need help $smarty in UDT [SOLVED]
PostPosted: Wed Jun 29, 2016 10:33 am 
Offline
Forum Members
Forum Members

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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
A2 Hosting