Copied to clipboard

Flag this post as spam?

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


  • Sébastien Richer 194 posts 430 karma points
    Jun 21, 2012 @ 16:21
    Sébastien Richer
    0

    Update from 4.7.1 to 4.7.2, macro parameters stopped working

    Hello,

    I updated my site from 4.7.1 to 4.7.2, and the macro attributes / parameters stopped working with my razor macros. I have this template that calls then from code, passing parameters, but on the receiving macro, not parameter is found. Here is code I use:

            var macros = new List<Macro>();
            foreach (var section in CurrentModel.GetChildrenAsList.Items)
            {
                if (section.NodeTypeAlias == "ListOfLinks")
                {
                    var macro = new Macro() { Alias = "ListOfLinks" };
                    macro.MacroAttributes.Add("NodeId", Convert.ToInt32(section.Id));
                    macros.Add(macro);
                }
                else if (section.NodeTypeAlias == "ListOfTitleTextImage")
                {
                    var macro = new Macro() { Alias = "ListOfTitleTextImage" };
                    macro.MacroAttributes.Add("NodeId", Convert.ToInt32(section.Id));
                    macros.Add(macro);
                }
            }
    
            var writer = new HtmlTextWriter(this.Output);
            foreach (var macro in macros)
            {
                macro.RenderControl(writer);
            }

    And then in those macros:

        @{
            if (!string.IsNullOrEmpty(GetParameter("NodeId")))
            {
                var nodeId = Convert.ToInt32(GetParameter("NodeId"));
                dynamic sectionNode = new DynamicNode(nodeId);
    
                if(!string.IsNullOrEmpty(sectionNode.titre)) { <h3>@sectionNode.titre</h3> }
    
                foreach (dynamic link in sectionNode.listeDeLiens)
                {
                    var target = "";
                    if (link.newwindow == "True")
                    {
                        target = " target=\"_blank\"";
                    }
    
                    <a href="@link.url"@Html.Raw(target)>@link.linktitle</a><br />
                }
            }
        }

    In this code, the parameter NodeId is always "". This was working correctly before the site update.

    Has anyone encountered a similar issue? Any ideas?

    Thanks for the help!

  • Sébastien Richer 194 posts 430 karma points
    Jun 21, 2012 @ 17:38
    Sébastien Richer
    0

    Apparently, wiring my parameter a different way works. But something in the update changed this. I wonder what it is.

    macro.Attributes.Add("NodeId", section.Id + "");
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 21, 2012 @ 19:13
    Dan Diplo
    0

    Have you looked at the Razor Components package? It should make working with dynamic macros a lot simpler.

  • John Walker 41 posts 136 karma points
    Jun 21, 2012 @ 19:56
    John Walker
    0

    Make sure that you have specified your parameters for the macro in the Umbraco back office. I believe 4.7.1 allowed you to pass parameters without specifying them which was a bug.

    John

  • Sébastien Richer 194 posts 430 karma points
    Jun 21, 2012 @ 20:03
    Sébastien Richer
    0

    Hi John,

    Yes I had that behavior in 4.7.1, those parameters were not required to exist in the back office. I had them anyways. On 4.7.2, I tried with the parameters speficied in the backoffice and without. But same behavior in both. I'm looking at the implementation in that Razor Components package to see if I can get a better way to go about this.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft