Copied to clipboard

Flag this post as spam?

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


  • Max 80 posts 437 karma points
    Feb 08, 2017 @ 18:32
    Max
    0

    macro container parameter values

    I'm calling a macro container (with a parameter value, that happens to be a content picker):

    @_section is type IPublishedContent if it has macrosContainer property the macro runs just fine.

    this document type is a composite, and may not always have the macrosContainer property editor. It works PERFECTLY... now i need to skip it in my view if the currentpage node id and the node id passed as the parameter value, are the same.

    ...stuff up here
    @Html.Raw(@_section.GetPropertyValue("macrosContainer"))
    ...stuff down here
    

    Can I pass in the parameter value from my view? (how so if possible?)

    Can I see what my parameter values are for the macro container from the view?

    is there something like:

    var paramV = @_section.GetProperty("macrosContainer").parameterValues;
    
  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Feb 09, 2017 @ 07:13
    Dennis Adolfi
    100

    Hi Max.

    Maybe I haven't understood the task, but instead of skipping the macroContainer in you view (based on the current node id) could'nt you just let the macro handle the skipping?

    I mean in your macro, check what the current page id is and if it is the same as the passed in parameter id, dont render anything.

    Example (in your macro):

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var contentpickerId = Model.MacroParameters["nodeId"].ToString();
        var currentNodeId = Model.Content.Id.ToString();
    }
    
    @if (contentpickerId != currentNodeId)
    {
        <div>
            @*Do stuff here!*@
        </div>
    }
    

    Could that work?

  • Max 80 posts 437 karma points
    Feb 10, 2017 @ 13:46
    Max
    0

    Conceptually, in terms of linear method/function execution, if I don't execute the macro until conditions have been met... I'd have a faster load time (?)... If I always call the macro and then check my conditions...I'm loading the macro if I don't have to...

    Is there a performance hit to calling "currentPage" from inside the macro at run time?

  • Max 80 posts 437 karma points
    Feb 10, 2017 @ 13:55
    Max
    1

    BTW,

    (Your idea did in fact solve the issue at hand.)

    int _sectionId = Convert.ToInt32(Model.MacroParameters["sectionId"]);
        int currentNodeId = Model.Content.Id;
    
        if (currentNodeId != _sectionId)
        {
    
            try
            {
                    IPublishedContent commissioners = Umbraco.TypedContent(_sectionId);
    ...more stuff after this...
    

    My philosophical debate remains, however :-) will there be caching/performance considerations? I have several of scenarios where I have macro containers loading conditionally in the view based on the parent node and its document type alias.

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Feb 13, 2017 @ 09:16
    Dennis Adolfi
    0

    Hi Max.

    Yes I get you debate.

    However I personally prefer letting the macro-component handle the conditional rendering instead of filtering it out in the template. The reason for that is that I might use the same macro across several different templates/doctypes, and I dont want to filter the macro-container based on parameters in every template. Instead I leave the rendering logic to the component self and then I can include it on whatever page I want, and I know that the conditional logic will be applied no matter what.

    But, hey! I guess there is no right or wrong way here. Do what feels comportable to you and what makes you sleep well at night. :)

    Until you find a way to do the filtering before rendering the macro, you can use the solution I provided. And if you find any performance/caching issues, please provide them to this thread and maybe it can help someone in the future.

    Take care, and have a great day!

Please Sign in or register to post replies

Write your reply to:

Draft