umbraco - 重复内容
我第一次使用 Umbraco 为客户设计网站。每个页面都由重复的内容面板组成 - 每个面板包含图像、标题和正文。
我的文档类型和模板非常适合内容面板。但是,我无法弄清楚如何向网页添加多个面板 - 我假设我设置主页文档类型以允许内容面板作为子节点 - 然后需要一个宏来迭代子节点并渲染每个都使用内容面板模板。
另外,我希望允许客户端也能够在每个页面中添加和删除面板。
有人可以给我一个宏代码的示例来执行此操作吗?非常感谢任何帮助!
I'm using Umbraco for the first time to design a website for a client. Each page consists of repeating content panels - each panel contains an image, title and body text.
I've got the document type and template working perfectly for the content panel. But, I can't work out how to add multiple panels to a web page - I'm assuming I set my main page doc type to allow the content panel as a child node - then need a macro to iterate the child nodes and render each using the content panel template.
Also, I would like to allow the client to be able to add and remove panels from each page as well.
Can someone give me an example of macro code to do this? Any help much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 Blog4Umbraco 包,您可以看到一个非常详细的示例,说明您正在尝试执行的操作。 (不想在这里跳过整个宏,但是您可以在此处找到它)将每个“面板”视为一篇博客文章,并查看在单个屏幕上显示最新 10 篇博客文章的 XSLT/宏 - 您可以轻松地根据您的需要进行调整正在做。您将为“面板”创建文档类型和模板,用户将为所需数量的面板创建内容,XSLT 的修改版本将循环遍历每个面板并在页面上显示信息。
如果您愿意(像我一样),您可以使用 asp.net 自定义控件来完成同样的事情,同样简单(特别是如果您对 .net 比 XSLT 更熟悉)。
使用如下代码创建一个模板:(此示例适用于一个简单的博客控件):
然后在页面加载后面的代码中,您可以将子项绑定到该中继器,如下所示:
If you look at the Blog4Umbraco package, you can see a very detailed example of what you are trying to do. (don't want to past the whole macro here, but you can find it here )Think of each "panel" as a blog post, and look at the XSLT/macro that shows the most recent 10 blog posts on a single screen - you could adapt that pretty easily to what you are doing. You would create a doctype and template for the 'panels', the user would create content for as many panels as you want, and a modified version of the XSLT would loop thru each and display the information on your page.
If you prefer (as I do), you can use an asp.net custom control to do the same thing just as easy (especillay if you are more familiar with .net than XSLT).
Create a template with code like this: (this example is for a simple blog control):
and then in the code behind page load, you can bind the children to that repeater like this: