Copied to clipboard

Flag this post as spam?

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


  • david weil 1 post 21 karma points
    Sep 22, 2011 @ 17:34
    david weil
    0

    How can set a js var to the value of a page property of the current page

    I have tried this:

    <script type="text/javascript">

    function foo()
    {
    var myprop = '<umbraco:item field="propField" runat="server" />';
    }
    </script>


    comes back empty

    then I tried this:

    <script type="text/javascript">

    function foo()
    {
    var myprop = '<%= umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("myProp").Value %>';
    }
    </script>

    for some reason GetCurrent() does not return the current page but the home page?

    any ideas

  • Eran 292 posts 436 karma points
    Sep 22, 2011 @ 19:10
    Eran
    0

    maybe this examples will help:

    this example is a working code inside razor macro:

     

    <script type="text/javascript">  
        @{
            var rootNode = Model.AncestorOrSelf(1);
            var thankYouNode = rootNode.ThankYouPage.First();
        }  
        var thankYouUrl = "@umbraco.library.NiceUrl(thankYouNode.Id)";
    </script>

    and this is working code inside xslt macro:

     

    <script type="text/javascript">
    var languageID =  "<xsl:value-of select='$languageID' />";
    </script>

    now you change the values that you need for your purpose, for example get the CurrentModel properties, etc.

     

Please Sign in or register to post replies

Write your reply to:

Draft