0

我有一个页面,其中一个占位符中有多个组件,不同的组件类型以及相同类型的多个组件。页面上有 3 个按特定顺序排列的组件。改变顺序被认为是可取的。选择组件允许移动组件,并且它看起来可以正常工作,直到点击保存,然后它就会消失。这与不久前的这个 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};

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

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

4

2 回答 2

1

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

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

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

布局定义.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;
};
于 2014-09-22T19:08:02.660 回答
0

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

页面编辑器检查插入控件的模板是否为 /sitecore/templates/System/Layout/Renderings/Sublayout 模板。如果控件不是基于该模板,则无法将控件标识为子布局。

在我的例子中,这个问题出现在 Sitecore 6.5 中,据说在 6.6 SP2 中已经修复,所以它肯定也会在 7.1 中修复。

于 2014-09-19T06:51:40.077 回答