3
votes

I'm having an issue with a rendering I'm building in Sitecore 8 Update 3, using MVC with Glass Mapper v4.

I have a Feature Promo rendering that has a Rendering Parameter Template Feature Promo Parameters which defines a droplist field named Align with the possible values Left and Right.

When in Experience Editor and Preview mode the rendering renders correctly and when debugging RenderingContext.Current["Parameters"] contains Align=Left or Align=Right accordingly, and Glass maps this correctly to my POCO.

However, when in web mode, the first rendering has Align=Left as its parameter, all subsequent renderings of the same type have Align with no value.

Checking the layout XML in the web database via Sitecore Rocks, I can see the parameters are there correctly:

<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) doesn't get the specified parameter value.

The code of the rendering is as follows:

@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 anyone advise what I'm doing wrong, or if I've found a random bug?

Update for Marek Musielak:

OK, its now only hitting the breakpoint once -- and has the uid of the first rendering on the page: {4CBD0824-D232-46F9-8763-295D3B493A4F}. Could this turn out to be something dynamic placeholders related?

RenderingContext.CurrentOrNull.Rendering["Parameters"] = "Align=Left"

1
Can you check what is RenderingContext.CurrentOrNull.Rendering.UniqueId value before executing var settings = ... code? Does it match concurrent rendering unique ids? And what is RenderingContext.CurrentOrNull.Rendering["Parameters"] value?Marek Musielak
@MarekMusielak added update.James Simm
Are other renderings displayed? Or just the first one? Can you login to sitecore desktop, switch to web database and check presentation details of you item? Do you have a code which hides renderings when datasource is missing? Are datasources/templates/other required items all published? When you say it works in Preview Mode and doesn't in Web Mode, I'm 90% sure it's all related to publishing. You can try to republish the whole site.Marek Musielak
Can you post the model for FeaturePromoParameters?Michael Edwards
Hi @MichaelEdwards, it is a simple POCO with a string property named "Align". Glass wasn't at fault here, my own stupidity and/or Sitecore caching being funny (see my answer below).James Simm

1 Answers

3
votes

This appears to be due to caching... oh the shame.

The renderings had Cacheable unchecked, and no other caching settings selected.

I've just updated them to have Cacheable checked and Vary by Parameters checked, re-published and its now working correctly.

I would have thought that having Cacheable off would mean the rendering would not be cached, but apparently not.

Thanks.