Copied to clipboard

Flag this post as spam?

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


  • Gonçalo Assunção 39 posts 68 karma points
    Aug 12, 2015 @ 21:36
    Gonçalo Assunção
    0

    Can't get document type value in macro

    Hi guys,

    I'm sure this is just one of those easy things, but I can't seem to see what's wrong, or find an anwser to this.

    I've created a document type for the root of the site, which as a dropdown datatype. The value of the dropdown is passed to the body as the id. This data type used to be a checkbox.

    It's is used like this:

    <umbraco:Macro runat="server" language="cshtml">
            @inherits umbraco.MacroEngines.DynamicNodeContext 
            @using umbraco.cms.businesslogic.web;
            @{
                var style = @Model.AncestorOrSelf(1).style.ToString();      
            }
            <body id="@style">
        </umbraco:Macro>
    

    As you can see, this macro is between the head and finishes after the body starting tag.

    I can get the value that I want to the id attribute of the body.

    Now, I need something similiar to this, but inside the head, to get the path of the favicon dynamically. But I'm not having any luck.

    When the document type was of type boolean, it worked. But know that I passed to a dropdown type, it gives me the macroscript error.

    Here's the code:

    <umbraco:Macro runat="server" language="cshtml">
            @inherits umbraco.MacroEngines.DynamicNodeContext 
            @using umbraco.cms.businesslogic.web;
            @{
            var favicon = "/HTML/Kultur/images/favicon.ico";
            var option = @Model.AncestorOrSelf(1).style;
    
            if(option == "normal")
            {
                favicon = "/HTML/Kultur/images/favicon.ico";
            }
            else if (option == "Style2")                
            {
                favicon = "/HTML/Kultur/images/faviconAlternative.ico";
            }
    
    
            }
            <link rel="icon" type="image/x-icon" href="@favicon" />
        </umbraco:Macro>
    

    If I hardcode "option = "normal"", works. But if I try to get the value of the dropdown, as I do in the id attribute for the body tag, it throws the Macro Script Error.

    I've tried to add the ".ToString()" at the end of the expression.

    Thank you all in advance

    Cheers from Portugal.

Please Sign in or register to post replies

Write your reply to:

Draft