编程在Sitecore的去除sublayoutsSitecore、sublayouts

由网友(笑颜如花)分享简介:有谁知道如何从Sitecore的项目中删除效果? 我想删除所有的sublayouts的,所以我可以用一组新的替换它们。我有tried这但它似乎并没有工作。该项目没有发生任何变化。我似乎能够得到的效果是这样的:RenderingReference []效果图= item.Visualization.GetRenderi...

有谁知道如何从Sitecore的项目中删除效果?

我想删除所有的sublayouts的,所以我可以用一组新的替换它们。 我有tried这但它似乎并没有工作。该项目没有发生任何变化。

我似乎能够得到的效果是这样的:

  RenderingReference []效果图= item.Visualization.GetRenderings(Sitecore.Context.Device,真正的);
 

但是,似乎没有办法再进行设置。

我也可以得到这样的效果图(从上面的链接):

  LayoutDefinition layoutDefinition = LayoutDefinition.Parse(LayoutField.GetFieldValue(item.Fields [Sitecore.FieldIDs.LayoutField]));
DeviceDefinition设备= layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());

如果(device.Layout!= NULL)device.Layout = NULL;
如果(!device.Renderings = NULL)device.Renderings =新的ArrayList();
 

但同样这也不行。清除从layoutDefinition设备,并设置了经过修改的,导致此异常:无连接可以作出,因为目标机器积极地拒绝它。而我现在根本无法查看的项目!

我觉得我找错了树,任何想法?

使用Sitecore的6.4 的

更新回复:techphoria414

code我想:

  layoutDefinition.Devices.Clear();
layoutDefinition.Devices.Add(设备);
 
C语言编程按要求删去部分输入时的字符

解决方案

我觉得你的例外是不相关的。要真正保存更改,您需要编辑的项目。请确保你始终可以访问和更新throgh值 LayoutField.Value

  LayoutField layoutField =新LayoutField(item.Fields [Sitecore.FieldIDs.LayoutField]);
LayoutDefinition布局= LayoutDefinition.Parse(layoutField.Value);
//进行更改到LayoutDefinition这里
item.Editing.BeginEdit();
layoutField.Value = layout.ToXml();
item.Editing.EndEdit();
 

Does anyone know how to remove the renderings from a Sitecore item?

I want to remove all of the sublayouts so I can replace them with a new set. I have tried this but it does not seem to work. Nothing changes on the item.

I appear to be able to get the renderings like this:

RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, true);

But there appears to be no way to then set them.

I can also get the renderings like this (from the link above):

LayoutDefinition layoutDefinition = LayoutDefinition.Parse(LayoutField.GetFieldValue(item.Fields[Sitecore.FieldIDs.LayoutField]));
DeviceDefinition device = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());

if (device.Layout != null) device.Layout = null;
if (device.Renderings != null) device.Renderings = new ArrayList();

But again this does not work. Clearing the device from the layoutDefinition and setting the modified one has led to this exception: No connection could be made because the target machine actively refused it. And I now cannot view the item at all!

I feel like I'm barking up the wrong tree, any ideas?

Using Sitecore 6.4

UPDATE Re: techphoria414

Code I tried:

layoutDefinition.Devices.Clear();
layoutDefinition.Devices.Add(device);

解决方案

I think your exception is unrelated. To actually save your changes, you need to edit the item. Be sure you always access and update the value throgh LayoutField.Value.

LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition layout = LayoutDefinition.Parse(layoutField.Value);
//make your changes to the LayoutDefinition here
item.Editing.BeginEdit();
layoutField.Value = layout.ToXml();
item.Editing.EndEdit();

阅读全文

相关推荐

最新文章