【发布时间】:2011-05-04 18:50:21
【问题描述】:
让我们用我的具体例子来解释:
我有 3 种类型(模板)的新闻:新闻、外部新闻、产品发布;
我想以不同的方式在主页上显示它们。
现在我正在我的 xsl 中做一个简单的操作:
<xsl:variable name="upcoming" select="./item[sc:formatdate(sc:fld('End Date',.),'yyyyMMdd') >= sc:formatdate($now,'yyyyMMdd')" />
<xsl:for-each select="$upcoming">
<div>
<h2>
<sc:text field="Name" />
</h2>
<p>
<sc:text field="Description" />
</p>
</div>
</xsl:for-each>
拳头解决方案是这样的(显然我不知道真正的语法):
<xsl:choose>
<xsl:when test="template = 'external news'">
<!-- something -->
</xsl:when>
</xsl:choose>
但更好的是更面向对象的方法,并有一个 make_body() 函数绑定到我可以从我的主页渲染中调用的项目。
Sitecore 是否有办法对可以在任何页面中显示的项目进行渲染?由项目本身处理的渲染?
你怎么看?
更新
我觉得我还不够清楚:
我想在我的主页上放一个最后的新闻框:
<div class="last_news">
<h2>Last News</h2>
<!-- Loop Goes here -->
</div>
我的不同新闻类型(新、外部新闻、产品发布)在该框中列出时具有不同的外观:
新:
<div class="news">
<h2><!-- title --></h2>
<p><!-- abridged text goes here --><p>
<a href="##news url##">read more</a>
</div>
外部新闻:
<div class="news external">
<img src="##website logo##">
<h2><!-- title --></h2>
<p><!-- abridged text goes here --><p>
<a href="##external url##">read more on www.<!-- site name --></a>
</div>
产品发布:
<div class="news product_release">
<div class="float_left">
<img src="##product logo##">
<a href="##product url##">Download now</a>
<a href="##product download url##">Download now</a>
</div>
<h2><!-- title --></h2>
<p><!-- abridged text goes here --><p>
<a href="##news url##">read more</a>
</div>
每种新闻类型都有自己的模板和不同的字段
- 新:标题、删节文本、全文
- 外部新闻:标题、删节文本、外部网址、网站选择框
- 产品发布:标题、删节文本、全文、产品选择框
我可以为每种类型制作子布局 (.ascx) 或渲染 (.xslt),但现在我想知道 如何在我的循环中显示它们。
我可以在循环中放置一个占位符,Sitecore 会知道当前项目必须使用该占位符吗?
【问题讨论】:
-
您是要坚持使用 XSLT(糟糕!)还是愿意切换到 C# 并使用子布局(用户控件)或编译的 Web 控件?
-
您尚未提供正在处理的 XML 文档。如果你这样做了,我会向你展示一个简单而优雅的 XSLT 解决方案。
-
我强烈建议您使用 C# 并同时使用子布局。 xsl 适合简单的解决方案,但当事情变得更复杂时,您可能需要切换到子布局/用户控件。
-
看看周围似乎子布局就是解决方案。现在我需要从所选项目中获取子布局并告诉它渲染我的项目?