gpt4 book ai didi

c# - 我可以从项目中获取渲染参数吗?

转载 作者:行者123 更新时间:2023-12-03 23:13:14 26 4
gpt4 key购买 nike

我的任务是查明我们的哪些子布局启用了缓存。我不是在谈论子布局上的缓存 - 我的意思是在渲染参数中设置的子布局的每个单独实例上的缓存。

这是我目前所做的:

  1. 分析我们网站的整个树,查看每个项目
  2. 获取每个项目的效果图
  3. 循环遍历每个渲染
  4. 检查是否在“缓存”部分设置了“可缓存”

我的问题是,我看到的“可缓存”设置是在子布局中设置的(在 Sitecore 中的布局 > 子布局下),而不是我在项目的子布局实例上设置的设置(我的项目 >展示 > 详情 > 点击控制)

我的代码是在单机上写的

1 号没问题 - 这是我对每个项目所做的:

2)

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

3)

foreach (RenderingReference r in renderings)

4)

bool cacheable = r.RenderingItem.Caching.Cacheable;

我似乎错过了获取每个子布局特定的渲染参数的步骤。但是,从我读过的指南来看,您似乎需要子布局本身才能访问这些参数。我找不到从项目或渲染引用中获取子布局的方法(也许有充分的理由?)。谁能帮助我进步?

Getting rendering parameters from sublayout

最佳答案

I have been tasked with finding out which of our Sublayouts have caching turned on. I'm not talking about the caching on the sublayout - I mean the caching on each individual instance of that sublayout as set in the rendering parameters.

通过引用 r.RenderingItem,您正在访问渲染的定义项,而不是演示详细信息中该子布局的“实例”。

要获取演示详细信息的每个实例的缓存,您可以使用:

RenderingReference[] renderings = Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, true);
foreach (var renderingReference in renderings)
{
// var isDefinitionItemCacheable = renderingReference.RenderingItem.Caching.Cacheable;
var isInstanceCacheable = renderingReference.Settings.Caching.Cacheable;
}

或者..

var sublayout = Parent as Sublayout;
if (sublayout != null)
{
var cacheable = sublayout.Cacheable;
}

关于c# - 我可以从项目中获取渲染参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14628806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com