Wrong render parameters on multiple renders
I am having a problem with a render I am creating in Sitecore 8 Update 3 using MVC with Glass Mapper v4.
I have a render Feature Promo
that has a render parameter template Feature Promo Parameters
that defines a droplist field with a name Align
with possible values Left
and Right
.
When in experience editor and in preview mode the render is displayed correctly, and when debugged RenderingContext.Current["Parameters"]
contains Align=Left
or Align=Right
respectively, and Glass displays this value correctly in my POCO.
However, when in web mode the first render has Align=Left
as its parameter, all subsequent renderings of the same type are Align
irrelevant.
Checking the XML layout in the web database via Sitecore Rocks, I can see the parameters are correct:
<r p:p="1" xmlns:p="p" xmlns:s="s">
<d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}">
<r p:before="r[@uid='{CAE5DB0F-1971-4931-939B-9F7DB14AF0F8}']"
s:ds="{F63266A5-CC62-4915-9D89-CB01C7A0D05A}"
s:id="{6BA52384-D976-499D-8A0D-7F729EB4376B}"
s:par="Align=Left" s:ph="main"
uid="{4CBD0824-D232-46F9-8763-295D3B493A4F}"/>
<r p:before="r[@uid='{12A7C72A-1821-4F8D-9A87-745604BE5106}']"
s:ds="{C50C7579-3680-46C3-93B2-9429EB9E0100}"
s:id="{6BA52384-D976-499D-8A0D-7F729EB4376B}"
s:par="Align=Right" s:ph="main"
uid="{CAE5DB0F-1971-4931-939B-9F7DB14AF0F8}"/>
<r p:before="*[1=2]" uid="{12A7C72A-1821-4F8D-9A87-745604BE5106}"/>
</d>
</r>
No matter what I do, the second (and any subsequent renderings of the same type) does not receive the specified parameter value.
The rendering code looks like this:
@model Promo
@{
var settings = Html.Glass().GetRenderingParameters<FeaturePromoParameters>();
var alignment = "feature-promo-style-a";
if (settings != null && settings.Align.EqualsText("Right")) {
alignment = "feature-promo-style-b";
}
}
<div class="feature-promo @alignment">
<div class="layout layout-a">
<div class="region region-a">
<div class="region-inner">
<div class="feature-promo-image-container">
@Html.Glass().Editable(m => m.Image)
</div>
<div class="block block-size-b feature-promo-text">
@if (Html.Glass().IsInEditingMode || !Model.PreTitle.IsEmptyOrNull()) {
<div class="pre-title">@Html.Glass().Editable(m => m.PreTitle)</div>
}
@if (Html.Glass().IsInEditingMode || !Model.Title.IsEmptyOrNull()) {
<h2 class="h3 color-a">@Html.Glass().Editable(m => m.Title)</h2>
}
@Html.Glass().Editable(m => m.Body)
</div>
</div>
</div>
</div>
</div>
Can someone please advise what I am doing wrong or if I found a random error?
Update for Marek Musielak:
OK, now it's only once hitting the breakpoint - and has uid first rendering on the page: {4CBD0824-D232-46F9-8763-295D3B493A4F}
. Could this turn out to be something to do with dynamic placeholders?
RenderingContext.CurrentOrNull.Rendering["Parameters"] = "Align=Left"
source to share
This is due to caching ... oh shame.
Rendering was Cacheable
unchecked and no other caching settings were selected.
I just updated it to be tested Cacheable
and Vary by Parameters
verified, republished and now it works correctly.
I would have thought that having Cacheable
off means the rendering would not be cached, but apparently not.
Thank.
source to share