Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sherry Ann Hernandez 320 posts 344 karma points
    Feb 09, 2011 @ 09:53
    Sherry Ann Hernandez
    0

    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.

  • Ernst Utvik 123 posts 235 karma points
    Feb 09, 2011 @ 10:04
    Ernst Utvik
    0

    Have not tried it myself yet, but there is a project for this: http://our.umbraco.org/projects/website-utilities/dictionary-2-javascript

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Feb 09, 2011 @ 10:28
    Stefan Kip
    0

    You can just use this:

    var someVarName = "<%= umbraco.library.GetDictionaryItem("yourDictionairyItemKey"%>";
  • Sherry Ann Hernandez 320 posts 344 karma points
    Feb 09, 2011 @ 11:50
    Sherry Ann Hernandez
    0

    @kipusoep - I've tried it but it is not working. It just return the actual string <%=umbraco.library.GetDictionaryItem("enter email address")%>

     

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Feb 09, 2011 @ 11:54
    Stefan Kip
    0

    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:

    <script type="text/javascript">
    var
    someVarName = "<%= umbraco.library.GetDictionaryItem("yourDictionairyItemKey") %>";
    </script>
  • Sherry Ann Hernandez 320 posts 344 karma points
    Feb 09, 2011 @ 12:12
    Sherry Ann Hernandez
    0

    but most of my script is in a js file. :( so it means it is not possible.

    Thanks though.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Feb 09, 2011 @ 12:18
    Stefan Kip
    1

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

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 20, 2015 @ 11:41
    Fuji Kusaka
    0

    Has anyone been able to get this working ?

  • Bjarne Fyrstenborg 1284 posts 4018 karma points MVP 8x c-trib
    Jun 20, 2015 @ 16:27
    Bjarne Fyrstenborg
    0

    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.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 21, 2015 @ 11:43
    Chriztian Steinmeier
    1

    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.

  • Tom Van Rompaey 38 posts 136 karma points
    Jun 21, 2015 @ 11:56
    Tom Van Rompaey
    0

    Most easy way to do this is just with razor on a template page:

    <script type="text/javascript">
    var test = '@Umbraco.GetDictionaryItem("DictionaryKey")';
    </script>
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 22, 2015 @ 05:19
    Fuji Kusaka
    0

    Hi guys,

    Ive tried to add same in my template

    <script>
        var name = "<%= umbraco.library.GetDictionaryItem("dicItem") %>";
    
    </script>
    

    But no success in the Js file where it needs to be within html

    var flap=$("<div class='fl'> dicItem needs to be here<span class='flLabel'/></div>");
    
  • Bjarne Fyrstenborg 1284 posts 4018 karma points MVP 8x c-trib
    Jun 22, 2015 @ 06:42
    Bjarne Fyrstenborg
    0

    @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:

    var flap=$("<div class='fl'>" + name + "<span class='flLabel'/></div>");
    

    Make sure the variable "name" is declared before this line and that the language is set.

    /Bjarne

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 22, 2015 @ 07:46
    Fuji Kusaka
    0

    Yes did that as well but not working.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 22, 2015 @ 07:57
    Fuji Kusaka
    0

    @Bjarne,

    I had my script all the way down, forgot to move it before the Js file.

    Yes works now.

    //Fuji

Please Sign in or register to post replies

Write your reply to:

Draft