« Return to Thread: Velocity Variables are accepted in JavaScript Array??

Re: Velocity Variables are accepted in JavaScript Array??

by bluejoe-2 :: Rate this Message:

Reply to Author | View in Thread

maybe the line $foo=bar is parsed as a legal JavaScript assignment statement
according to Florin Vancea's suggestion
if you have a look at the source codes in web browser
you may get the answer

----- Original Message -----
From: "Int64" <vineetbindal@...>
To: <user@...>
Sent: Friday, June 12, 2009 10:50 AM
Subject: Re: Velocity Variables are accepted in JavaScript Array??


>
> #set($foo = "bar")
> suggest.push("$foo")
> suggest.push($foo)//Actually this also works.. if i do it like this
> $foo="bar"//instead of #set($foo = "bar")
>
> but if $foo=(some value coming from database such as)//$foo=$value//then it
> does not work.
>
> i donno why it was behaving like this
>
> Byron Foster-2 wrote:
>>
>> Looking at the generated javascript should reveal all. If in Velocity  
>> you say
>>
>> #set($foo = "bar")
>> suggest.push("$foo")
>> suggest.push($foo)
>>
>> will render as:
>>
>> suggest.push("bar")
>> suggest.push(bar)
>>
>> When the javascript runs the second line is referencing a variable  
>> 'bar' which is not defined, and will cause a javascript error.
>>
>> If you have the error console running in your browser, you should see  
>> javascript errors to this effect.
>>
>> On Jun 11, 2009, at 6:24 , Int64 wrote:
>>
>>> Your suggestion for suggestions.push("$show"); really worked,
>>>
>>> But can you please explain why suggestions.push($show);was not  
>>> working and
>>> it was not working with my values from database(it was working for
>>> hard-coded values). and why your suggestion worked??
>>>
>>> bluejoe-2 wrote:
>>>>
>>>> if $show is a string, you can try
>>>> suggestions.push("$show");
>>>>
>>>> VTL renders on server-side
>>>> while javascript executes on browser
>>>>
>>>> yours,
>>>> bluejoe
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@...
>> For additional commands, e-mail: user-help@...
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Velocity-Variables-are-accepted-in-JavaScript-Array---tp23956244p23992058.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4101 (20090525) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

 « Return to Thread: Velocity Variables are accepted in JavaScript Array??