ps : pass var from tpl to php

63 views
Skip to first unread message

daniel...@googlemail.com

unread,
Jul 3, 2014, 7:46:23 PM7/3/14
to smarty-d...@googlegroups.com
Hi every one

i want to try pass value from tpl file to php like this :

{assign var='anything' value=333 }

or

{include_file file='somepage.tpl' anything=3}



then :

in php file callback this value like this

$myVar=$param['anything'];

echo $myVar;


output : 333

----- or use a class for callback request method ------------------
class sys_request{

//what 's code for here

}




$myVar = sys_request('anything',$_REQUEST['anything']);
echo $myVar;

output : 333


i dont know more about smarty functions please help me for true answer .

 thank for help
good luck.

uwe.tews

unread,
Jul 3, 2014, 8:00:48 PM7/3/14
to smarty-d...@googlegroups.com
See http://www.smarty.net/docs/en/plugins.functions.tpl

You can write a function plugin like

function smarty_function_foo ($params, $template) {
  $myvar = $params['anything'];
....
}

and call it from the template as
{foo anything = $anything}

is that what you are looking for?

Daniel Elvito

unread,
Jul 4, 2014, 9:01:42 AM7/4/14
to smarty-d...@googlegroups.com
tanx a lot
good luck

On 7/4/14, uwe.tews <uwe....@googlemail.com> wrote:
> See http://www.smarty.net/docs/en/plugins.functions.tpl
>
> You can write a function plugin like
>
> function smarty_function_foo ($params, $template) {
> $myvar = $params['anything'];
> ....
> }
>
> and call it from the template as
> {foo anything = $anything}
>
> is that what you are looking for?
>
>
> Am Freitag, 4. Juli 2014 01:46:23 UTC+2 schrieb daniel...@googlemail.com:
>>
>> Hi every one
>>
>> i want to try pass value from tpl file to php like this :
>>
>> {assign var='anything' value=333 }
>>
>> or
>>
>> *{include_file file='somepage.tpl' anything=3}*
>>
>>
>> then :
>>
>> in php file callback this value like this
>>
>>
>>
>> *$myVar=$param['anything'];echo $myVar;*
>>
>> *output : 333*
>>
>> ----- or use a class for callback request method ------------------
>>
>>
>>
>>
>> *class sys_request{//what 's code for here}*
>>
>>
>>
>>
>>
>>
>> *$myVar = sys_request('anything',$_REQUEST['anything']);echo $myVar;output
>>
>> : 333*
>>
>> i dont know more about smarty functions please help me for true answer .
>>
>> thank for help
>> good luck.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Smarty Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to smarty-develop...@googlegroups.com.
> To post to this group, send email to smarty-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/smarty-developers.
> For more options, visit https://groups.google.com/d/optout.
>

Mark Rogers

unread,
Jul 4, 2014, 9:37:19 AM7/4/14
to smarty-d...@googlegroups.com
On 4 July 2014 00:46, <daniel...@googlemail.com> wrote:
i want to try pass value from tpl file to php like this :

It's been a while since I needed to do this but I used to do it like this:
    {assign var='anything' value=333}
then
    $smartyVars = $smarty->getTemplateVars();
    $myVar = $smartyVars['anything'];

(My specific use case was an email class that used Smarty to render the email content, and allowed the template to pass back constructed values for things like the email subject.)

--
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450
Registered in England (0456 0902) 21 Drakes Mews, Milton Keynes, MK8 0ER
Reply all
Reply to author
Forward
0 new messages