如何在 Orchard 中设置小部件的样式?
我正在尝试在 Orchard 中构建一个主题(转换现有的模板),但在设计博客档案小部件时遇到了困难。我有一个区域“侧边栏”,我在其中放置了小部件。
为了让它输出我想要的标记,我在视图文件夹中创建了一个新模板: Widget-BlogArchives.cshtml 所有模板都会将小部件的内容包装在 div 中,如下所示:
<div class="box box_small">
@Display(Model.Content)
</div>
所以我希望所有小部件内容在我的 div 里面。然而生成的 HTML 看起来像这样:
<article class="widget-blog-archives widget" shape-id="15">
<header shape-id="15">
<h1 shape-id="15">The Archives</h1>
</header>
<div class="box box_small" shape-id="15">
<div class="archives" shape-id="16">
<ul class="archiveMonthList" shape-id="16">
<li class="first last" shape-id="16">
<a href="(shortened)/10" shape-id="16">October 2011 (1)</a>
</li>
</ul>
</div>
</div>
</article>
我不明白的是整个文章的换行是从哪里来的?如何将标题放入我的 div 并将其更改为 a ?
有人还可以解释一下模型中标题“档案”的存储位置吗?我在形状追踪工具中查看了模型,但找不到它......
谢谢。
更新
正如 Bertrand 所解释的,我对 Widget-BlogArchives.cshtml 进行了一些更改:
@using Orchard.ContentManagement
@using Orchard.Widgets.Models
@{
Model.Metadata.Wrappers.Clear();
var title = ((IContent)Model.ContentItem).As<WidgetPart>().Title;
}
<div class="box box_small">
<h3>@title</h3>
@Display(Model.Content)
</div>
这现在会生成我想要的 HTML。
I am trying to build a theme (convert an existing template I have) in Orchard but I got stuck when styling the Blog Archives widget. I have a zone "sidebar" in which I placed the widget.
In order to have it output the markup I want I created a new template in my views folder: Widget-BlogArchives.cshtml All the template does it wrap the content of the widget in a div like so:
<div class="box box_small">
@Display(Model.Content)
</div>
So I expected all the widget content to be inside my div. However the generated HTML looks like this:
<article class="widget-blog-archives widget" shape-id="15">
<header shape-id="15">
<h1 shape-id="15">The Archives</h1>
</header>
<div class="box box_small" shape-id="15">
<div class="archives" shape-id="16">
<ul class="archiveMonthList" shape-id="16">
<li class="first last" shape-id="16">
<a href="(shortened)/10" shape-id="16">October 2011 (1)</a>
</li>
</ul>
</div>
</div>
</article>
What I don't understand is where the whole article wrapping is coming from? How can I get the header into my div and change the to a ?
Could someone also please explain where in the Model the title "The Archives" is stored? I looked through the model in the shape tracing tool but couldn't find it...
Thanks.
UPDATE
As Bertrand explained I made some changes to my Widget-BlogArchives.cshtml:
@using Orchard.ContentManagement
@using Orchard.Widgets.Models
@{
Model.Metadata.Wrappers.Clear();
var title = ((IContent)Model.ContentItem).As<WidgetPart>().Title;
}
<div class="box box_small">
<h3>@title</h3>
@Display(Model.Content)
</div>
This now generates the HTML I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该标记来自小部件包装器。可以通过调用 Model.Metadata.Wrappers.Clear() 来抑制包装器。然后,您可以完全接管您自己的小部件覆盖的渲染。
如果您打开 widget.wrapper.cshtml,您将找到第二个问题的答案:
也可以通过以下方式完成:
This markup comes from the widget wrapper. It is possible to suppress the wrapper by calling Model.Metadata.Wrappers.Clear(). You can then completely take over the rendering from your own widget override.
If you open widget.wrapper.cshtml, you'll find the answer to your second question:
Which could also be done this way: