Sitecore页面编辑器移动和添加组件的问题

时间:2014-09-18 17:06:08

标签: sitecore page-editor sitecore7.1

我有一个页面,在一个占位符中包含多个组件,不同的组件类型以及相同类型的多个组件。页面上按特定顺序有3个组件。认为改变订单是合乎需要的。选择组件允许移动组件,它似乎正常工作,直到点击保存,然后它消失。这与前一段时间here的SO帖子非常相似。我还没有发现任何迹象表明此错误已得到修复。作为参考,我使用的是Sitecore 7.1(rev.140324)。

在此之后,尝试向页面添加相同类型的组件也不起作用。通过演示详细信息将页面重置为初始状态后,显然向占位符添加组件时会遇到问题。现在,解决方法是通过演示文稿详细信息操作页面,这对内容编辑器没有帮助。解决方法需要在字段中显式输入占位符,并在适用的情况下嵌套页面上的所有组件。

Sitecore日志未显示任何内容。浏览器控制台显示"无法解析命令参数"移动组件后两次。相关的javascript:

this.parseCommandClick = function(commandClick) {
var msg = commandClick;
var commandParams = null;
var idx1 = commandClick.indexOf("(");
var idx2 = commandClick.indexOf(")");
if (idx1 >= 0 && idx2 > idx1) {
  msg = commandClick.substring(0, idx1);
  try {
    commandParams = $sc.evalJSON(commandClick.substring(idx1 + 1, idx2));
  }
  catch (e) {
    console.log("Cannot parse command parameters");
  }
}

return { message: msg, params : commandParams};

如果在页面的标准值中设置了演示文稿详细信息,则不会为某些组件指定占位符,也不会为其他组件嵌套。可以通过删除添加组件的特定占位符然后移动它们并保存来将问题复制到其他位置。这会导致组件被删除。我不确定控制台日志与此直接相关。

我想弄清楚为什么会发生这种情况。

2 个答案:

答案 0 :(得分:1)

看来,默认情况下,Sitecore是默认工作的(从7.1开始),而不是修改和配置的问题。创建新实例后,我可以通过标准值中的演示详细信息向页面添加组件来重新创建问题。问题产生于将占位符字段留空。如果是这种情况,则向页面添加组件会显示消息:“发生错误”并且移动组件通常会导致删除。因此,解决此问题的方法是更改​​所有受影响项目的标准值。当Sitecore处理空字段时,似乎会发生一些有趣的事情。这是我用来绕过这个问题的方法。

Sitecore支持回复了一个额外的解决方法,以避免数据丢失:

  

将附加的布局定义文件放入   \ Website \ sitecore \ shell \ Applications \ Page Modes文件夹并清除   浏览器缓存(替换您的js文件)。此脚本可防止组件   删除并显示以下消息:“组件是可视的   移动但是如果移动组件,某些信息可能会丢失   PE。请保存更改(如果禁用保存则重新加载)   查看实际演示文稿并通过演示文稿移动组件   详细信息(功能区上的“高级”选项卡)。“请注意这一点   解决方法未经过深入测试,我们建议您备份   应用任何更改之前的解决方案。

LayoutDefinition.js

Sitecore.LayoutDefinition = new function() {
};

Sitecore.LayoutDefinition.insert = function(placeholderKey, id) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);

  var r = new Object();
  r["@id"] = id;
  r["@ph"] = placeholderKey;

  device.r.splice(0, 0, r);

  this.setLayoutDefinition(layoutDefinition);
};

Sitecore.LayoutDefinition.getRendering = function(uid) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);
  if (!device) {
    return null;
  }

  for (var n = 0; n < device.r.length; n++) {
    if (this.getShortID(device.r[n]["@uid"]) == uid) {
      return device.r[n];            
    }
  }
};

Sitecore.LayoutDefinition.remove = function(uid) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);

  this.removeRendering(device, uid);  
  this.setLayoutDefinition(layoutDefinition);
};

Sitecore.LayoutDefinition.removeRendering = function(device, uid) {
  for (n = 0; n < device.r.length; n++) {
    if (this.getShortID(device.r[n]["@uid"]) == uid) {
      r = device.r[n];
      device.r.splice(n, 1);
      return r;
    }
  }
  return null;
};

Sitecore.LayoutDefinition.moveToPosition = function(uid, placeholderKey, position) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);
  var originalPosition = this._getRenderingPositionInPlaceholder(device, placeholderKey, uid);

  for (var totalCount = 0; totalCount < device.r.length; totalCount++)
  {
    var rendering = device.r[totalCount];       
    if (rendering["@ph"]=="")
    {
       window.alert('The component is visually moved but some information could be lost if you move the component in PE.  Please save the changes (reload page if save is disabled) in order to see actual presentation and move the component via the Presentation Details (Advanced tab on the Ribbon).');   
      return;
    }
  }


  var r = this.removeRendering(device, uid);
  if (r == null) {
    return;
  }

  r["@ph"] = placeholderKey;

  if (position == 0) {
     device.r.splice(0, 0, r);
     this.setLayoutDefinition(layoutDefinition);
     return;
  }
  // Rendering is moving down inside the same placeholder. Decrement the real position, because rendering itself is removed 
  // from his original position. 
  if (originalPosition > -1 && originalPosition < position) {
    position--;
  }

  var placeholderWiseCount = 0;
   var flag = true;
  for (var totalCount = 0; totalCount < device.r.length; totalCount++)
  {
    var rendering = device.r[totalCount];       
    if (Sitecore.PageModes.Utility.areEqualPlaceholders(rendering["@ph"], placeholderKey))
    {
      placeholderWiseCount++;
    }

    if (placeholderWiseCount == position)
    {    
      device.r.splice(totalCount + 1, 0, r);
      break;
    }
  }

  this.setLayoutDefinition(layoutDefinition);
};

Sitecore.LayoutDefinition.getRenderingConditions = function(renderingUid) {
  if (!Sitecore.PageModes.Personalization) {
    return [];
  }

  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);
  var conditions = [];
  for (var i = 0; i < device.r.length; i++) {
    if (this.getShortID(device.r[i]["@uid"]) == renderingUid && device.r[i].rls) {
      var rules = device.r[i].rls.ruleset;
      if (rules && rules.rule) {
        if(!$sc.isArray(rules.rule)) {
          rules.rule = [rules.rule];
        }

        for (var j = 0; j < rules.rule.length; j++) {
          var conditionId = rules.rule[j]["@uid"];
          var isActive = Sitecore.PageModes.Personalization.ConditionStateStorage.isConditionActive(renderingUid, conditionId);
          conditions.push(new Sitecore.PageModes.Personalization.Condition(
            conditionId,
            rules.rule[j]["@name"],
            isActive
          ));
        }
      }
    }
  }

  return conditions;
};

Sitecore.LayoutDefinition.GetConditionById = function(conditionId) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);  
  for (var i = 0; i < device.r.length; i++) {
     var rules = device.r[i].rls ? device.r[i].rls.ruleset: null;
     if (rules && rules.rule) {
        if(!$sc.isArray(rules.rule)) {
          rules.rule = [rules.rule];
        }

        for (var j = 0; j < rules.rule.length; j++) {
          if (rules.rule[j]["@uid"] == conditionId) {
            return {rule : rules.rule[j]};
          }
        }
     }
  }

  return {};
};

Sitecore.LayoutDefinition.getRenderingIndex = function(placeholderKey, index) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);

  var i = 0;

  for (n = 0; n < device.r.length; n++) {
    if (device.r[n]["@ph"] == placeholderKey) {
      if (i == index) {
        return n;
      }

      i++;
    }
  }

  return -1;
};

Sitecore.LayoutDefinition.getRenderingPositionInPlaceholder = function(placeholderKey, uid) {
  var layoutDefinition = this.getLayoutDefinition();
  var device = this.getDevice(layoutDefinition);
  return this._getRenderingPositionInPlaceholder(device, placeholderKey, uid);
};

Sitecore.LayoutDefinition.getLayoutDefinition = function() {
  return JSON.parse($sc("#scLayout").val());
};

Sitecore.LayoutDefinition.setLayoutDefinition = function(layoutDefinition) {
  var newValue = $sc.type(layoutDefinition) === "string" ? layoutDefinition : JSON.stringify(layoutDefinition);
  if ($sc("#scLayout").val() != newValue) {
    $sc("#scLayout").val(newValue);
    Sitecore.PageModes.PageEditor.setModified(true);
  }
};

Sitecore.LayoutDefinition.getDeviceID = function() {
  return $sc("#scDeviceID").val();
};

Sitecore.LayoutDefinition.getDevice = function(layoutDefinition) {
  var deviceID = this.getDeviceID();

  if (!layoutDefinition.r.d) {
    return null;
  }

  //By serialization behaivour. If there is single element- it would not be serialized as array
  if (!layoutDefinition.r.d.length) {
    layoutDefinition.r.d = [layoutDefinition.r.d];
  }

  var list = layoutDefinition.r.d;

  for (var n = 0; n < list.length; n++) {
    var d = list[n];

    var id = this.getShortID(d["@id"]);

    if (id == deviceID) {
      //By serialization behaivour. If there is single element- it would not be serialized as array
      if (d.r && !d.r.length) {
        d.r = [d.r];
      }
      return d;
    }
  }

  return null;
};

Sitecore.LayoutDefinition.getShortID = function(id) {
  return id.substr(1, 8) + id.substr(10, 4) + id.substr(15, 4) + id.substr(20, 4) + id.substr(25, 12);
};

Sitecore.LayoutDefinition.readLayoutFromRibbon = function() {
  var layout = Sitecore.PageModes.PageEditor.ribbon().contentWindow.$("scLayoutDefinition").value;    
  if (layout && layout.length > 0) {
    this.setLayoutDefinition(layout);
    return true;
  }

  return false;
};

Sitecore.LayoutDefinition._getRenderingPositionInPlaceholder = function(device, placeholderKey, uid) {
  var counter = 0;
  for (var i = 0; i < device.r.length; i++) {
    if (Sitecore.PageModes.Utility.areEqualPlaceholders(device.r[i]["@ph"],placeholderKey)) {
      if (this.getShortID(device.r[i]["@uid"]) == uid) {
        return counter;
      }

      counter++;
    }
  }

  return -1;
};

答案 1 :(得分:0)

阅读this博文,您可能会遇到同样的问题。简而言之,问题(已被报告为错误)是:

  

页面编辑器检查插入控件的模板是否为   / sitecore / templates / System / Layout / Renderings / Sublayout模板。   如果控件不是基于该模板,则控件不能   被确定为Sublayout。

在我的情况下,问题出现在Sitecore 6.5中,并且据说在6.6 SP2中修复了,所以它肯定会在7.1中修复。