Sitecore Multilist with Search

Usually when using Sitecore Multilist with search, it returns all the versions of the item, I can use the following extra condition to the Filter parameter:  StartSearchLocation=<ITEM_ID>&Filter=_latestversion:true

This will result to show only the latest version of the item.

Toggle place holders based on Sitecore page mode

Sometimes we want to show the generic callouts in Page Editor mode but we don’t want to show the callout wrapper if there is no callouts being set in Sitecore.

Let’s say we have the following html:

<div class=“module-three-column”>
    <div class=“module-three-column-box”>
        <sc:Placeholder ID=“phCallout1” runat=“server” Key=“Left Single Row Callout” />
    </div>
    <div class=“module-seperator”></div>
    <div class=“module-three-column-box”>
        <sc:Placeholder ID=“phCallout2” runat=“server” Key=“Center Single Row Callout” />
    </div>
    <div class=“module-seperator”></div>
    <div class=“module-three-column-box”>
        <sc:Placeholder ID=“phCallout3” runat=“server” Key=“Right Single Row Callout” />
    </div>
</div>

I don’t want to show this control at all if any of the placeholders don’t have controls.

Here is the code behind:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Sitecore.Context.PageMode.IsPageEditor)
            {
                if (!phCallout1.HasControls() && !phCallout2.HasControls() && !phCallout3.HasControls())
                {
                    this.Visible = false;
                }
            }
        }

I just check to if this is not page editor mode then I check if any of the placeholders has any controls, if not don’t display the control in the front end.

It works like a charm.

Sitecore FieldRenderer

Before and After attributes in the Sitecore FieldRender allows the mark up to  be wrapped when needed, so it doesn’t render the mark up when the field is empty.

Says the markup is something like:

<h2 class="page-header">
<sc:FieldRenderer ID="frTitle" FieldName="Title" runat="server" />
</h2>

I can do this instead:

<sc:FieldRenderer ID="frTitle" FieldName="Title" runat="server" 
Before="<h2 class='page-header'>" After="</h2>"/>

Hello

This is my first blog post. I’m so glad to be here.