简单的答案是你无法在页面上获取另一个子布局的子布局参数。
这是因为在对该子布局发出请求并将参数添加到管道中的请求之前不会传递参数(如果我没记错的话,参数是在管道中传递的,而不是在上下文中传递 - 无论如何,这对两者都适用)。
因此,获取不同子布局参数的唯一方法是:
1. 如果您在父子布局中并且正在查看子子布局控件上的参数您在代码中自己设置的
2. 如果您通过一些过于繁琐的代码(您可以通过其他方式更轻松地执行某些操作)进入 Sitecore,请在 Presentation Details 中获取添加到页面的所有子布局,并查看每个子布局的参数。但是请注意,此解决方案只为您提供在 Sitecore 中设置的参数。
这两种解决方案都不会给您在另一个子布局的代码隐藏中设置的参数。
第二种解决方案不是一个好的解决方案,因为它会很混乱且过于复杂。如果您真的需要像这样共享参数数据,您应该做的是扩展 Sitecore 上下文(这可能比您正在做的工作更多),或者使用 Session 共享数据(这是可能是最适合您的解决方案,但请确保您不要过度使用它;与任何事情一样,在开始使用之前研究Session)。
编辑
如果您正在寻找有关在请求中传递的参数的更多信息,您需要反编译 Sitecore.Kernel.DLL 并手动进行调查。没有这方面的文档,除了可能隐藏在某个地方的博客文章中的一两个宝石。
关于您关于编写“调用请求和检索参数的函数”的评论,我会强烈建议不要这样做。这是一个非常丑陋的解决方案,如果我们完全了解您的用例,很容易被更好的解决方案所取代。
编辑 2
在你的评论中,你说:
我有一个项目树,其中一些可能有也可能没有
具有所需的参数(例如,一个复选框)。 A -> B
-> C -> D ,如果我在页面 D,我想迭代到父节点,直到我找到复选框被选中。
从这个评论中,我相信你错误地使用了“参数”这个词来代替“字段”。 Field 是添加到模板中的控件(如Signle-Line Text field、Rich-Text Field、Checkbox Field、Multilist Field等),在模板上给定一个标题,可以通过一个用户。相反,参数是传递给子布局的键值对,其语法与查询字符串相同。参数设置在演示详细信息中,而字段设置在项目本身(或其 __Standard 值或继承的 __Standard 值)上。
如果我是正确的并且您误用了“参数”一词,那么您根本不想做您所描述的事情。您要做的只是以下几点:
// looking for the youngest item from the context item through its ancestors that has the "Foo" check box checked
var youngestItemWithFoo = Sitecore.Context.Item; //give the found item a name
bool foundYoungestChecked; //will be our loop condition/flag to show we found the youngest that has the box checked
// we need the root path to ensure that we do not go too far up the tree
var rootPath = Sitecore.Configuration.Factory.GetSite("website").RootPath;
// Foo is a checkbox field - the below checks raw values to see if foo is checked.
// ** Note that the way that this condition is written, the root item (often the "Home" item)
// will still be checked but the loop will not traverse farther up the tree. You may need
// to change this to stop the traversal sooner, depending on your solution **
while (!(foundYoungestChecked = youngestItemWithFoo["Foo"] == "1") && youngestItemWithFoo.Paths.Path != rootPath)
{
youngestItemWithFoo = youngestItemWithFoo.Parent; // if the Foo field is not checked, look at the parent and continue
}
//make sure that an item was found, as it is possible that none were
if (foundYoungestChecked)
{
//...item was found - do your stuff...
}
else
{
//...item was not found - do some other stuff...
}