Sitecore MVC Ensure empty placeholder is selectable in experience editor

☆樱花仙子☆ 提交于 2019-12-12 18:16:48

问题


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>

回答1:


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.



回答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);
    }
  }
}



回答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>


来源:https://stackoverflow.com/questions/32626544/sitecore-mvc-ensure-empty-placeholder-is-selectable-in-experience-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!