简体   繁体   English

Umbraco可编辑内容块

[英]Umbraco Editable Content Block

I am new to Umbraco and looking to add a static content block to my website that my client can edit with a WYSIWYG. 我是Umbraco的新手,希望在我的网站上添加一个静态内容块,我的客户可以使用所见即所得进行编辑。 I come from a Joomla/Wordpress background where this could be accomplished with a HTML Module (Joomla) or Widget(Wordpress). 我来自Joomla / Wordpress背景,可以使用HTML模块(Joomla)或Widget(Wordpress)来完成。 Does anyone know how to set something like this up in Umbraco? 有谁知道如何在Umbraco中设置类似的内容?

This is possible, I have created similar blocks in the past with XSLT, but of course it can be done with WebControls or MVC as well. 这是可能的,我过去使用XSLT创建了类似的块,但是当然也可以使用WebControls或MVC来完成。

First, on the DocumentTypes where you want to display the static content block, add a new field called StaticBlocks. 首先,在要显示静态内容块的DocumentTypes上,添加一个名为StaticBlocks的新字段。 The type could be a multilist or dropdown or so, whatever you prefer as long as you can choose at least one (ContentBlock) item from the content-tree. 只要您可以从内容树中选择至少一个(ContentBlock)项目,该类型就可以是多列表或下拉列表等。

You need to create a new Document type, call it ContentBLock and add a RichText field to it. 您需要创建一个新的Document类型,将其称为ContentBLock并向其中添加一个RichText字段。 This is your static content block. 这是您的静态内容块。

Also create a template for this ContentBlock and make sure the template is rendered somewhere in your main layout. 还要为此ContentBlock创建一个模板,并确保将该模板呈现在主布局中的某个位置。 This template only contains a Macro (in my case it was an XSLT macro). 该模板仅包含一个宏(在我的情况下,它是一个XSLT宏)。 The XSLT Macro reads the selected nodeID from the StaticBlocks field from your currentPage, get the node by using the <xsl:variable name="node" select="umbraco.library:GetXmlNodeById($nodeID)" /> method (this is the ContentBLock). XSLT宏会从currentPage的StaticBlocks字段中读取所选的nodeID,并使用<xsl:variable name="node" select="umbraco.library:GetXmlNodeById($nodeID)" />方法获取<xsl:variable name="node" select="umbraco.library:GetXmlNodeById($nodeID)" /> (这是ContentBLock)。 Output the value of the Richt Text Field from your ContentBlock. 从您的ContentBlock输出Richt Text Field的值。

That should do the trick. 这应该够了吧。 You can extend this by selecting random blocks from a pre-selected list or rotate blocks between page refresh, etcetera. 您可以通过从预先选择的列表中选择随机块或在页面刷新之间旋转块等来扩展此范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM