Search DXM Forum
Here's my scenario:
I have a child template where I use the Out.Wrap Template API call for the master page portion (header, footer, etc).
I want to exclude certain parts of the master page template based on a value that is found in the child template.
How can I pass the value to the master? Or how can I reach the value from the master? Other suggestions and approaches are also welcome.
I was thinking I could use the context object to hold this value, as shown below. It hasn't worked so far:
***storing the value in child template
string other; if (asset.GetContent().TryGetValue("remove_right_nav_buttons", out other)) { context.UserVariables["remove_right_nav_buttons"] = other; }
***accessing the value in master template
StringBuilder sbContent = new StringBuilder(); if (context.UserVariables["remove_right_nav_buttons"] == "true") { string componentMarkupNoRightButtons = @"html"; sbContent.Append(componentMarkupNoRightButtons); } else sbContent.Append(componentMarkup);
Thank you, @morenoCami , for posting a question in the Crownpeak Community. I am a member of the Customer Success team and would like to help answer this question with the help of my friend, @DavidGreenberg, from Crownpeak Support.
After some back and forth, our recommendation is this:
We would love for you to try this and let us know if this solves your question. If so, appreciate if you would mark this as solved so others looking for the same answer can easily find it.
Good luck!
@BeverlyDunn and @DavidGreenberg
You do not need to do anything if you are using Out.Wrap. The parameter that you pass to the method is a template rather than an asset so the asset does not change in the output context. You can verify this yourself by outputing asset.Id in both the child and the navigation wrapper templates and you'll see that the output is the same.
However, if you are using Asset.Show to get the rendered output of another asset, then you will need to use the mechanism you outlined (UserVariables).
This example code code demonstrates:
Navigation Wrapper template:
<div class="tester" style="border: 1px solid silver; width; 100%"> <p>Asset ID: <%= asset.Id %></p> <p>var1: <%= context.UserVariables["var1"] %></p> <p>var2: <%= context.UserVariables["var2"] %></p> </div>
Child template:
<% context.UserVariables["var1"] = "set before call"; Out.Wrap("/path/navigation-wrapper"); context.UserVariables["var2"] = "set after call"; %>