Catch A smarty variable in a user defined tags

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
whyggy

Catch A smarty variable in a user defined tags

Post 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.
cyberman

Re: Catch A smarty variable in a user defined tags

Post 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;
Last edited by cyberman on Thu Sep 14, 2006 5:12 pm, edited 1 time in total.
Piratos

Re: Catch A smarty variable in a user defined tags

Post by Piratos »

The user defined function you need is this:


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


Thats all.
whyggy

Re: Catch A smarty variable in a user defined tags

Post 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...
Piratos

Re: Catch A smarty variable in a user defined tags

Post 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.
Last edited by Piratos on Sun Sep 24, 2006 5:54 pm, edited 1 time in total.
whyggy

Re: Catch A smarty variable in a user defined tags

Post 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.
Locked

Return to “Modules/Add-Ons”