No it doesn't mean it's not possible. If you declare a var like this, it'll be a global var. You can use this var in script files which you include after this line of code...
Usually I use the approach, which @kipusoep discribes - define global variables in the master template and then access them from javascript files included after the script block in the master template.
If the text you need to use is in any way related to something that's being rendered, I will usually render it as a data-attribute on the element, which I can then grab from the JS file later, when needed.
use dictionary item in javascript
Is it possible to use the umbraco dictionary item in javascript?
We also want all the alert messages to be multilingual.
Have not tried it myself yet, but there is a project for this: http://our.umbraco.org/projects/website-utilities/dictionary-2-javascript
You can just use this:
@kipusoep - I've tried it but it is not working. It just return the actual string <%=umbraco.library.GetDictionaryItem("enter email address")%>
You should put that code line of code in the markup of a masterpage (template, not .js file) and surround it with script tags, like this:
but most of my script is in a js file. :( so it means it is not possible.
Thanks though.
No it doesn't mean it's not possible. If you declare a var like this, it'll be a global var.
You can use this var in script files which you include after this line of code...
Has anyone been able to get this working ?
Usually I use the approach, which @kipusoep discribes - define global variables in the master template and then access them from javascript files included after the script block in the master template.
If the text you need to use is in any way related to something that's being rendered, I will usually render it as a data-attribute on the element, which I can then grab from the JS file later, when needed.
Most easy way to do this is just with razor on a template page:
Hi guys,
Ive tried to add same in my template
But no success in the Js file where it needs to be within html
@Fuji
If you print the variable name to the console, do you then see a value for "name"?
console.log(name);
Then you should be able to use it like this:
Make sure the variable "name" is declared before this line and that the language is set.
/Bjarne
Yes did that as well but not working.
@Bjarne,
I had my script all the way down, forgot to move it before the Js file.
Yes works now.
//Fuji
is working on a reply...