在不同的 Sitecore 项目类型上有不同的显示
让我们用我的具体例子来解释一下:
我有 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>
产品release :
<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>
每种新闻类型都有自己的模板,包含不同的字段
- new:标题、节选文本、全文
- 外部新闻:标题、节选文本、外部 url、网站选择框
- 产品发布:标题、节选文本、全文、产品选择框
I可以做一个每种类型的子布局 (.ascx) 或渲染 (.xslt),但现在我想知道如何在循环中显示它们。
我可以在循环中放置一个占位符吗?Sitecore 会知道当前项目必须使用该占位符吗?
Let's explain with my specific example :
I have 3 types(template) of news : new, external news, product release;
I want to display them on the home page in different manners.
For now I'm doing a simple in my 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>
Fist solution would be something like that (obviously i don't know the real syntax):
<xsl:choose>
<xsl:when test="template = 'external news'">
<!-- something -->
</xsl:when>
</xsl:choose>
But better yet would be a more object oriented approach and have a make_body() function Bound to the item that i could call from my home page rendering.
Or does Sitecore have a way to do a rendering of an item that can displayed in any pages; a rendering handled by the items itself ?
What do you think ?
Update
I think i was not clear enough:
I want in my home page a last news box:
<div class="last_news">
<h2>Last News</h2>
<!-- Loop Goes here -->
</div>
My different news types(new, external news, product release) have different appearances when they are listed in that box :
new:
<div class="news">
<h2><!-- title --></h2>
<p><!-- abridged text goes here --><p>
<a href="##news url##">read more</a>
</div>
external news:
<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>
product release :
<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>
Each News types has it's own template with different fields
- new: title, abridged text, full text
- external news: title, abridged text, external url, website select box
- product release: title, abridged text, full text, product select box
I can make a sublayouts (.ascx) or renderings (.xslt) for each type but now i want to know how to display those in my loop.
Can i put an placeholder inside my loop and Sitecore will know that placeholder must be use by the current item ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这个问题的答案完全取决于你要显示什么样的内容。您可以将任何想要的内容放入富文本字段中,并使其对于该项目是唯一的。这是迄今为止最简单的解决方案,对我来说最有意义......但也许我误解了你想要做什么。但我相当确定您不想在 XSLT 中执行此操作。 (当然,我有偏见......我在 XSLT 中没有做任何事情)
如果我真的必须根据模板使渲染表现不同,我会使其成为带有代码隐藏的子布局。将业务逻辑放入 XSL 中是没有意义的。
还可以动态地将子布局添加到占位符。毕竟,这就是 Sitecore 在后端所做的事情...因此您可以根据您要显示的(随机?)项目指定特定的子布局,并将数据源设置为您的项目。
I think the answer to this depends entirely on what kind of content you are going to display. You could put anything you want in a Rich text field and have it be unique to the Item. This is by far the easiest solution and makes the most sense to me... but maybe I'm misunderstanding what you are trying to do. But I'm fairly certain you don't want to do this in XSLT. (of course, I'm biased... I don't do anything in XSLT)
If I really had to make the rendering behave different depending on the template, I would make it a sublayout with code-behind. It just doesn't make sense to put business logic in XSL.
It's also possible to dynamically add a sublayout to a placeholder. After all, this is what Sitecore is doing on the back end... So you could specify the particular sublayout depending what (random?) item you are displaying and set the datasource to your item.
也许我遗漏了一些东西,但是您不能将每个模板的渲染(xslt)和子布局(asp.net 控件)绑定到该模板的演示文稿吗?
与其创建一个“复杂”的 if 或 switch 来处理不同的模板,不如为每个模板创建一个简单的?
例如。您将拥有这些 asp.net 控件:
否则,如果您更喜欢使用 1 xslt,因为它们有很多共享字段,您可以使用该
功能。我想你会这样写:
然后你只需为每个模板制作一个。警告我不能 100% 确定 @template='x' 是正确的语法。
我希望这有帮助。
Maybe I'm missing something, but couldn't you just have a rendering (xslt) og sublayout (asp.net control) per template bound to the presentation of that template?
Instead of creating a "complex" if or switch to handle different templates, make one simple per template?
Eg. you'd have these asp.net controls:
otherwise if you prefer using 1 xslt, because they have a lot of shared fields, you could use the
functionality. I think you'd write it something like this:
And then you just make one for each template. Warning I'm not 100% sure that @template='x' is the correct syntax.
I hope this helps.