Retrieve custom assigned template variable in a UDT [SOLVED]

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Retrieve custom assigned template variable in a UDT [SOLVED]

Post by antosha »

Hi,
I want to share a little problem that I faced today while writing a UDT that would perform a str_replace.
This is my cms template :

Code: Select all

...
{capture assign=mycustomvariable}{content block="Fruits" wysiwyg="false"}{/capture}
{mycustomudt}
...
and this is the UDT mycustomudt :

Code: Select all

global $gCms;
$healthy = array("apple", "orange", "pear");
$yummy   = array("pizza", "beer", "ice cream");

$yummyoutput = str_replace($healthy, $yummy, $mycustomvariable);
echo $yummyoutput ;
Now, when I look at my page in a browser, nothing shows up.
I suspect that for some reason the UDT doesn't retrieve $mycustomvariable...
What am I doing wrong?

Thanks :)
Last edited by antosha on Sun Jun 20, 2010 8:58 pm, edited 1 time in total.
Follow me on twitter: end_tone
Linked In: levchenkoanton
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Retrieve custom assigned template variable in a UDT

Post by calguy1000 »

use this:

Code: Select all

$mycustomvariable = $smarty->get_template_vars('my_custom_vars');
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
NaN

Re: Retrieve custom assigned template variable in a UDT

Post by NaN »

Or try this:

Code: Select all


...
{capture assign=mycustomvariable}{content block="Fruits" wysiwyg="false"}{/capture}
{mycustomudt var="$mycustomvariable"}
...

Code: Select all


$mycustomvariable = '';
if(isset($params['mycustomvariable']))
         $mycustomvariable = $params['mycustomvariable'];

$healthy = array("apple", "orange", "pear");
$yummy   = array("pizza", "beer", "ice cream");

$yummyoutput = str_replace($healthy, $yummy, $mycustomvariable);
echo $yummyoutput;

You can pass any param to udts or plugins named whatever you want: {udt foo=bar}
All these params are stored in an array named $params indexed with their param names.
So within the udt or plugin you can access that param via $params['foo']. (wich will return 'bar')
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: Retrieve custom assigned template variable in a UDT

Post by antosha »

Thanks for your replies,
I tried both solutions and still no luck, the the block on the page shows empty. Could this happen beacause I am still running CMSMS 1.6.7?
Follow me on twitter: end_tone
Linked In: levchenkoanton
NaN

Re: Retrieve custom assigned template variable in a UDT

Post by NaN »

Just take a closer look at the code.
There is a small error.
In the template i used var="mycustomvariable".
But in the code i refer to $params['mycustomvariable'] which is indeed wrong.
Regarding to my last explanations (foo=bar => $params['foo'])
It should be $params['var'].
Last edited by NaN on Sun Jun 20, 2010 8:40 pm, edited 1 time in total.
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: Retrieve custom assigned template variable in a UDT

Post by antosha »

I should have seen this...
Thanks a lot, it works great now !
Follow me on twitter: end_tone
Linked In: levchenkoanton
Post Reply

Return to “The Lounge”