Copied to clipboard

Flag this post as spam?

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


  • Hugh Loughrey 5 posts 46 karma points
    Jul 08, 2015 @ 11:43
    Hugh Loughrey
    0

    Macro Parameters

    Hey, so i appreciate that this has been asked before...but I'm still stuck.

    So I'm using Umbraco v7.2.6 ad I'm trying to create a macro which has a true/false parameter which I need to render as a either true or false string on the page. I appreciate that the true/false data type returns 0 or 1 an that you therefore need to convert...but I'm having no luck.

    The code in my cshtml is:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var footer = "";
        var hideFooter = @Model.MacroParameters["data-gist-hide-footer"];
        if (hideFooter.Equals("0")) {
            footer = "true";
        } else {
            footer = "false"
        }
    }
    
    <div>@footer</div>
    

    But when I run the page i get:

    Error loading Partial View script (file: ~/Views/MacroPartials/footer.cshtml)
    

    Any advice for an umbraco novice would be great...cheers! :)

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 08, 2015 @ 11:47
    Ismail Mayat
    100

    In umbracoSettings.Config update the bit

        <MacroErrors>inline</MacroErrors>
    

    to

    <MacroErrors>throw</MacroErrors>
    

    Then hit page again you should get full error this will help to debug.

    Regards

    Ismail

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Jul 08, 2015 @ 18:07
    Sebastiaan Janssen
    0

    Dashes might be invalid characters in macro paramater aliases (don't remember for sure). Worth a try to rename the parameter and try again.

  • Hugh Loughrey 5 posts 46 karma points
    Jul 10, 2015 @ 11:19
    Hugh Loughrey
    0

    Hey Ismail & Sebastiaan,

    Thanks for your pointers, I got the debugger to display more info and renamed my parameters and managed to get the macro working:

    var foo = Model.MacroParameters["bar"];
    if (foo.Equals("1"))
    {
        foo = "true";
    }
    else
    {
        foo = "false";
    }
    

    Every day's a school day! :) Cheers Hugh

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies