Page 1 of 1

Catch A smarty variable in a user defined tags

Posted: Thu Sep 14, 2006 2:32 pm
by whyggy
Hi,

I have some problem with sending variables.

In the module news ,in my action.default.php I assign this variable.

Code: Select all

$this->smarty->assign('max', $max);
Do you think we can display this variable in an user defined tags ?

I know we can show this variable in the template with

Code: Select all

{$max}
But i really need to use in an UDT.

Thx a lot for any idea !
W.

Re: Catch A smarty variable in a user defined tags

Posted: Thu Sep 14, 2006 5:10 pm
by cyberman
I'm not a coder for real (have too much to learn yet :)) but have you tried to define $max as global variable in action.default.php?

Code: Select all

global $max;

Re: Catch A smarty variable in a user defined tags

Posted: Thu Sep 14, 2006 5:35 pm
by Piratos
The user defined function you need is this:


echo $smarty->get_template_vars('max');


Thats all.

Re: Catch A smarty variable in a user defined tags

Posted: Sun Sep 24, 2006 5:25 pm
by whyggy
Thx Cyberman & piratos,

But, when I tried to do "

Code: Select all

 print_r( $smarty->get_template_vars() );
" on my UDT, I don't have the variables assigned in my action.default.php !

When I tried with the global solutions.
In my action.default.php :

Code: Select all

		global $test;
		$test = "toto";
and in my UDT

Code: Select all

		global $test;
		echo $test;
Nothing is displaying, the variables is empty...

Re: Catch A smarty variable in a user defined tags

Posted: Sun Sep 24, 2006 5:49 pm
by Piratos
Assign the variable as you have posted and use the tag - i have tested it - it works


$variable = $smarty->get_template_vars();

print_r ($variable)

that works too

there exist a plugin function smarty_cms_function_get_template_vars that you can use.

Re: Catch A smarty variable in a user defined tags

Posted: Tue Sep 26, 2006 3:16 pm
by whyggy
Yeah !!
Thankx Piratos !

Your first code was working, but only displaying these variables.

Code: Select all

Array
(
    [SCRIPT_NAME] => /index.php
    [app_name] => CMS
    [sitename] => CMS Made Simple Site
    [lang] => 
    [encoding] => UTF-8
    [content_id] => 52
    [page] => resultat
    [page_id] => resultat
    [page_name] => resultat
    [page_alias] => resultat
    [position] => 00003
    [friendly_position] => 3
)
I put the UDT with

Code: Select all

$variable = $smarty->get_template_vars();

print_r ($variable) 
in my template, and now i have all my variables !!!
Thx a lot sincerely.
W.