2

Is there some trick with placeholders in Sitecore MVC to ensure that they are always selectable in the page editor experience editor even when they don't contain any renderings? My controller rendering declares the placeholder in the cshtml view as follows:

<div>
  <!-- some html markup and fields rendered here --> 
  @Html.Sitecore().Placeholder("my-component-placeholder")
</div>
Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120
  • You mean you are having a problem seeing empty placeholders in the xEditor? If so, make sure you have the placeholder defined in layout/placeholder settings. – RvanDalen Sep 17 '15 at 09:17
  • I already have a placeholder settings item defined for it. – Matthew Dresser Sep 17 '15 at 09:18
  • Are you logged in as admin? With settings present and placeholder key has an exact match then you should see a canvas area. Otherwise I've experienced a situation where it looked like it wasnt rendering but it contained a rendering which returned html markup with 0 height. – RvanDalen Sep 17 '15 at 09:22
  • 4
    Have you checked the `Editable` option on the placeholder item? – jammykam Sep 17 '15 at 10:38
  • @jammykam I had experimented with that, but it 'appeared' not to work. Turns out that it was a CSS issue... – Matthew Dresser Sep 17 '15 at 11:04

3 Answers3

7

To ensure placeholder visibility and selectability, you need to ensure the following:

  1. A placeholder settings item exists in Sitecore with the correct Placeholder Key matching that declared in the cshtml rendering.
  2. The placeholder settings item has the Editable setting checked.
  3. The CSS in the page is not preventing the placeholder from being visible.
Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120
  • 1
    There also used be an issue when using uppercase characters in placeholder names, not sure if this has been fixed yet or not, I opt for all lowercase: http://sitecorepromenade.blogspot.co.uk/2014/12/sitecore-7x-mvc-and-placeholder.html – jammykam Sep 17 '15 at 12:41
  • @jammykam yes its still a problem unless you install the fix. After trying everything else we changed the case and the problem disappeared. About an hour later stumbled on this https://kb.sitecore.net/articles/296299 Funny thing is I'm using Sitecore 8 and its still there. – Fred Sep 22 '15 at 15:36
  • @Fred Ha! I hadn't seen that article. I've always used all lowercase, just a personal preference, so had never seen the issue... – jammykam Sep 22 '15 at 15:42
3

In case you are using some kind of dynamic placeholder keys, there is a setting that controls if empty placeholders without settings are editable. It is located in the Sitecore.ExperienceEditor.config.

WebEdit.PlaceholdersEditableWithoutSettings

The default value is false. If set to true, empty placeholders can be edited:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <settings>
            <setting name="WebEdit.PlaceholdersEditableWithoutSettings">
                <patch:attribute name="value">true</patch:attribute>
            </setting>
        </settings>
    </sitecore>
</configuration>
Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67
nsgocev
  • 4,390
  • 28
  • 37
2

Solved by setting Query.MaxItems:

<setting name="Query.MaxItems">
  <patch:attribute name="value">1000</patch:attribute>
</setting>

Explanation:
In large projects you may have a lot of placeholders (more then 260 what is default amount of items Sitecore Query API reads at one time).

Sitecore team set the limitation but Placeholder cache was not fixed and still reads items only once so as a result placeholders which weren't added into cache because of the limitation are skipped.

This is the code of the cache manager taken from reflector:

public virtual void Reload()
{
  lock (FieldRelatedItemCache.Lock)
  {
    this.itemIDs = new SafeDictionary<string, ID>();
    Item[] local_1 = this.Database.SelectItems(string.Format("{0}//*[@@templateid = '{1}']", (object) this.ItemRoot.Paths.FullPath, (object) this.ItemTemplate));
    if (local_1 == null)
      return;
    foreach (Item item_0 in local_1)
    {
      string local_3 = item_0[this.FieldKey];
      if (!string.IsNullOrEmpty(local_3) && !this.itemIDs.ContainsKey(this.GetCacheKey(local_3)))
        this.Add(local_3, item_0);
    }
  }
}
Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67
ALZ
  • 101
  • 1
  • 3