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;
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.
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?
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.
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.
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.
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:
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):
Could that work?
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?
BTW,
(Your idea did in fact solve the issue at hand.)
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.
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!
is working on a reply...