0

We have a view that uses rendering parameters, one of which sets a model property that determines whether a form should show inside the view. When I change the default value to 1 for that checkbox, the checkbox appears checked when I edit that rendering on a page, but the form doesn't show up. I've made sure that the standard values for that set of rendering parameters is published and even republish the page the rendering is on to no avail. The only thing that seems to work is to uncheck the checkbox, publish, then recheck the checkbox and publish yet again.

Note that this is happening only for existing renderings. If you add a new rendering of this type it works as expected.

Here is the controller colde:

public ActionResult AZList()
        {
            if (Sitecore.Context.PageMode.IsExperienceEditorEditing && String.IsNullOrEmpty(RenderingContext.Current.Rendering.Parameters["Item Types"]))
                return Content("<div><h3>Use the component properties for this widget to select the item types you wish to display</h3></div>");

            var includeSearch = "0";
            if (!(String.IsNullOrEmpty(RenderingContext.Current.Rendering.Parameters["Show Search Field"])))
                includeSearch = RenderingContext.Current.Rendering.Parameters["Show Search Field"].ToString();

            var model = new AZModel();
            model.searchForm = includeSearch == "1" ? true : false;

            var orgRoot = ORG.Utility.ORGUtils.GetRoot(Sitecore.Context.Item);
            var allItems = new List<Sitecore.Data.Items.Item>();

            // determine what kinds of items are in this list from the rendering parameters
            var allItemTypes = RenderingContext.Current.Rendering.Parameters["Item Types"];

            // if somehow nothing was selected, bail out
            if (String.IsNullOrEmpty(allItemTypes)) return null;

            var itemTypes = allItemTypes.Split('|');
            var ORGRegion = orgRoot.Parent.Axes.GetDescendants().Where(x => x.Name.StartsWith("All ")).FirstOrDefault();
            var queryORG = "/sitecore/content/ORGs//*[@@id='" + orgRoot.ID.ToString() + "']//*[@@templateid='";
            var queryRegion = "|/sitecore/content/ORGs//*[@@id='" + ORGRegion.ID.ToString() + "']//*[@@templateid='";
            var queryGlobal = "|/sitecore/content/ORGs/All ORGs//*[@@templateid='";
            for (var i = 0; i < itemTypes.Length; i++)
            {
                var typeId = itemTypes[i];

                var guid = new Guid(typeId);
                var id = ID.Parse((Guid)guid);
                var typeInfo = Sitecore.Context.Database.GetItem(id);

            if (typeInfo == null)
                {
                    logger.Info("Could not find item with ID '" + typeId + "'");
                    continue;
                }

                var squery = queryORG + typeInfo["Data Template"] + "']";
                squery += queryRegion + typeInfo["Data Template"] + "']";
                squery += queryGlobal + typeInfo["Data Template"] + "']";

                // get all the items of the given typeId beneath the root
                var templateItems = Sitecore.Context.Database.SelectItems(squery).ToList();

                // see if there are any items
                if (templateItems.Any())
                {
                    // see what controller & view to use
                    var controller = typeInfo["Controller Name"];
                    var view = typeInfo["View Name"];

                    logger.Info("Controller: " + controller + ", View: " + view);

                    string nameField = "Title";

                    // add them to the model
                    model.Items.AddRange(templateItems.Select(x => new ListItem
                        {
                            Model = x,
                            Controller = controller,
                            Name = x[nameField],
                            View = view
                        }
                    ));
                }
            }

            // iterate through items to see what letters we should activate
            foreach(char c in AZModel.ALPHABET)
            {
                // select from allItems where name/title/whatever toLower starts with c
                if(model.Items.Where(x => x.Name.ToLower().StartsWith(c.ToString())).Any())
                {
                    // if any, add this character to the string in our model
                    model.Letters += c;
                }

            }
            model.Title = RenderingContext.Current.Rendering.Parameters["Title"];
            model.Description = RenderingContext.Current.Rendering.Parameters["Content"]; ;

            return View(model);
        }

... and here is the view code:

@model ORG.Models.AZModel
@using ORG.Models

<h2 class="azHeader">@Model.Title</h2>
<div class="azDesc">@Html.Raw(Model.Description)</div>
@if (Model.searchForm)
{
    using (Html.BeginForm())
    {
        <div id="searchControls" class="inputBTNcombo w-reset">
            <div>
                <label class="visiblyHidden" for="searchListText">Search</label>
                <input type="text" id="searchListText" value="@Model.SearchText" name="searchListText" placeholder="Search the list..." />
                <button class="preferredAction" type="submit" id="searchListButton" value="Search">Search</button>
            </div>
            <button type="reset" id="btnReset">Clear Search Results</button>

        </div>
    }
    if (!(String.IsNullOrEmpty(Model.SearchText)))
    {
        var resultWord = Model.Items.Count == 1 ? "result." : "results.";
        <div>
            <span class='searchResultsText'>
            Your search <span class='searchResultsTextBold'>'@Model.SearchText'</span> returned @Model.Items.Count @resultWord
            </span>
        </div>
    }
}
<div class="module contentFeed A-Z-Dir">
    <div class="feedUtilities">
        <div class="pageSelector">
            @{
                if (Model.Letters != null)
                {
                    foreach (char l in AZModel.ALPHABET)
                    {
                        if (Model.Letters.Contains(l))
                        {
                            <a href="#@l">@Char.ToUpper(l)</a>
                        }
                        else
                        {
                            <a disabled="disabled">@Char.ToUpper(l)</a>
                        }
                    }
                }
            }
        </div>
    </div>
    <div class="A-Z-DirList">
        @{
            if (Model.Letters != null)
            {
                foreach (char l in AZModel.ALPHABET)
                {
                    if (Model.Letters.Contains(l))
                    {
                        <h2 class="dirLetter" id="@l" name="@l">@Char.ToUpper(l)</h2>
                        foreach (var item in Model.Items.Where(x => x.Name.StartsWith(l.ToString(), StringComparison.CurrentCultureIgnoreCase)).OrderBy(x => x.Name))
                        {
                            Html.RenderAction(item.View, item.Controller, new { Model = item.Model });
                        }
                    }
                }
            }
        }
    </div>
</div>
<script type="text/javascript" src="~/_inc/js/src/AZList.js"></script>
  • not sure this will work but could you please try after publishing your rendering templates? – Mahendra Shekhawat Sep 17 at 16:16
  • Yes, I've done that, and it doesn't do anything. – Levi Wallach Sep 17 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.