Copied to clipboard

Flag this post as spam?

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


  • Graham Carr 277 posts 389 karma points
    Mar 04, 2013 @ 17:17
    Graham Carr
    0

    Razor Macro Property Issue

    I have a macro called "Boxes" that is calling a Razor script and I have a property on this macro named "ChosenBoxes". On the templates that have this macro added, it is called as such:

    <umbraco:Macro ChosenBoxes="[$pageRhsBoxes]" Alias="Boxes" runat="server"></umbraco:Macro>

    Now $pageRhsBoxes is an alias for a custom data type utilising a Multi-Node Tree Picker.

    The issue I am having is that if no nodes are selected within the multi-node picker for a particular page, then in my macro code, it is always giving me back node ids for nodes selected within the multi-node picker of a parent page. The code is as follows:

    @{
    if(Parameter.ChosenBoxes != "")
    {
    string[] boxIds = Parameter.ChosenBoxes.Split(',');
    if (boxIds.Length > 0)
    {
    foreach (string boxId in boxIds)
    {
    Node box = new Node(Convert.ToInt32(boxId));
    switch (box.NodeTypeAlias)
    {
    case "EnquiryForm":
    @Library.RenderMacro("RHSEnquiryForm");
    break;
    case "RecentNews":
    @Library.RenderMacro("RightRecentNews");
    break;
    case "Downloads":
    @Library.RenderMacro("RightDownloadList");
    break;
    }
    }
    }
    }
    }

    If I debug the script in Visual Studio, I can see that the ChosenBoxes parameter has IDs even if none have been selected in the multi-node picker.

    Has anyone come across this before, or have any ideas as to the cause?

  • Graham Carr 277 posts 389 karma points
    Mar 04, 2013 @ 17:23
    Graham Carr
    0

    I have just found the issue, I was unaware that referencing a paramter with the $ sign makes it recursive whereas referencing with a # takes the page value. All found on the following page:

    http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters/advanced-macro-parameter-syntax

     

  • 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