• 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.  [ 3 posts ] 
Author Message
 Post subject: Variable assigned in UDT is NULL in template
PostPosted: Sat Mar 16, 2019 11:16 pm 
Offline
Forum Members
Forum Members

Joined: Sun Feb 03, 2008 8:14 pm
Posts: 75
Well, mystified by this one!

I have a udt, lets call it "myudt"
Code:
.......
.......
echo "<pre>Dump1";
var_dump($foo);
echo "</pre>";
$smarty->assignGlobal('foo', $foo);


Then in a template in CMSMS2.2.9.1
Code:
{myudt}
<pre>Dump2
{$foo|@var_dump}
</pre>
<pre>Dump3
{get_template_vars}
</pre>

The resultant displayed data is:
- At Dump1 complete and as expected
- At Dump2 it is null
- At Dump3 it shows up as a variable available with all data complete and correct ???!! (at least to the smarty command {get_template_vars}

(ps. working on a module for use in the CMSMS2x world but the inspiration comes from defunct CMSMS1x module - so I'm guessing now - something different with parsing module templates through Smarty between v1 and v2 ?) - I'll have another read of the module writing tutorial


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Variable assigned in UDT is NULL in template
PostPosted: Sun Mar 17, 2019 10:47 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7650
Location: The Netherlands
Code:
$foo = 'bar';
$smarty->assignGlobal('foo', $foo);

Code:
{myUDT}
{$foo}

Quote:
bar

This works for me, if not for you in your UDT the value for $foo isn't set before...

_________________
Image

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Variable assigned in UDT is NULL in template  Topic is solved
PostPosted: Sun Mar 17, 2019 3:23 pm 
Offline
Forum Members
Forum Members

Joined: Sun Feb 03, 2008 8:14 pm
Posts: 75
Thank you for your reply Rolf

Read it and thought "i know all that and thats isn't going to work either! " - (my bad >:D :-[ ),but tried it for proof (with displays of $foo in the template after the UDT and again in the page after the module's template) and it all worked :. why ? what is different ?

On closer examination of myudt, the issue was I had (because I thought I needed it)
Code:
global $smarty;
$tpl_vars = $smarty->getTemplateVars();

As my first line - and as the last line
Code:
$smarty->assignGlobal("foo", $foo);

everything worked in the UDT and as my original post said in the template after the UDT (or in the page after the module's template) $foo is NULL but $foo is present if I do {get_template_vars}

But your example code prompted me to go back and correct/remove my erroneous first line of code: "global $smarty" that was causing this. Now the variable has data in the module's template and in the page

Many thanks for your help Rolf - all good now


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.  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: fbarraza28


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:  
A2 Hosting