我的HTML代码如下:
<a data-toggle="dropdown">Associate Sites<i class="fa fa-angle-down"></i></a>
使用Sitecore MVC字段:
@Html.Sitecore().BeginField("Link Field", new { @data_toggle = "dropdown" })
@Html.Sitecore().Field("Destination URL", item.Item, new { @data_toggle = "dropdown" })<i class="fa fa-angle-down"></i>
@Html.Sitecore().EndField()
结果:
<a href="/en" data_toggle="dropdown">Associate Sites</a> <i class="fa fa-angle-down"></i>
预期结果:
<a href="/en" data_toggle="dropdown">Associate Sites<i class="fa fa-angle-down"></i></a>
请帮助我,如何将Bootstrap图标集成到Sitecore字段中。
答案 0 :(得分:1)
您只需要以下内容:
@Html.Sitecore().BeginField("Destination URL", item.Item, new { @data_toggle = "dropdown" })
<i class="fa fa-angle-down"></i>
@Html.Sitecore().EndField()
这将输出以下HTML:
<a href="/my-url" data_toggle="dropdown">My Page Name
<i class="fa fa-angle-down"></i>
</a>
由于您在解决方案中明显使用Glass Mapper,因此您应该使用此功能,而不是使用Sitecore字段助手和&#34;魔术字符串&#34;
@Html.Glass().Editable(Model, x => x.DestinationURL,
string.Format("<a href=\"{0}\" data-toggle=\"dropdown\">{1}<i class=\"fa fa-angle-down\"></i></a>", x.DestinationURL.Url, x.DestinationURL.Text))