|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
gelogelo Smarty n00b
Joined: 10 Jul 2009 Posts: 2
|
Posted: Fri Jul 10, 2009 7:35 pm Post subject: assign php_variable into Javascript function argument in Sm |
|
|
Dear communitarians,
how is it possible to assign a php-variable from php script into a javascript function argument via Smarty->assign("variable', $variable);
i used {literal} and {ldelimit} {rdelimit} and never got the value passed
code within the Smarty-template:
<td width="1%" align="center" valign="left" class="content"><img src="picture.jpg" alt="picture"
onMouseOver="T_func({$variable})" onMouseOut="Unfunc()"></td>
I want to pass the value of $variable to the Javascript-function T_func()
Thanks for your advices! |
|
Back to top |
|
philoertel Smarty Rookie
Joined: 25 Jun 2009 Posts: 14 Location: Chicago, IL
|
Posted: Fri Jul 10, 2009 8:57 pm Post subject: |
|
|
If all you want is
Code: | <td width="1%" align="center" valign="left" class="content"><img src="picture.jpg" alt="picture"
onMouseOver="T_func({$variable})" onMouseOut="Unfunc()"></td> |
what you have there will do it. Did you try it just like that? You don't need {literal} or {ldelimit}. Smarty will turn T_func({$variable}) into T_func(12345) or whatever you assigned to {$variable}. Just be careful what you put in that variable. Unless it's really simple variable like an int or a string with no special chars, use json_encode:
Code: | $smarty->assign('variable', json_encode(array('a' => 1, 'b' => 2))); |
_________________ Phil Oertel
Application Developer
http://www.soliantconsulting.com |
|
Back to top |
|
gelogelo Smarty n00b
Joined: 10 Jul 2009 Posts: 2
|
Posted: Sat Jul 11, 2009 8:09 am Post subject: SOLVED: smarty assigned variable to Javascript function |
|
|
Dear phil,
just this is the problem:
Code:
<td width="1%" align="center" valign="left" class="content"><img src="picture.jpg" alt="picture"
onMouseOver="T_func({$variable})" onMouseOut="Unfunc()"></td>
does NOTHING onMouseOver.
Thats the reason i asked.
Infact it's a string ( $variable ) i need to pass to the Javascript function argument (and a tooltip rectangle to be created);
so i tried also : onMouseOver="T_func('{$variable}')"
And now it works!
Thanks for your Help,
Gunter |
|
Back to top |
|
jLix Smarty Regular
Joined: 01 Apr 2009 Posts: 59 Location: Lowlands, EU
|
Posted: Mon Jul 13, 2009 12:15 am Post subject: |
|
|
TIP: always have a look in the source code of your browser when things are not going according to plan in order to see what the result of the PHP/Smarty parsing looks like. Too often developers only look at their server side code although it is the front-end code, recieved by the browser, that tells the browser what to do. _________________ http://jlix.net/extensions/smarty |
|
Back to top |
|
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|