我正在Umbraco中创建一个动态的Bootstrap列。如何仅将类别“ col-md-offset-1
”分配给列“ col-md-2
”中的第一个孩子?
@{
foreach (IPublishedContent list in homeList.Where(x => x.IsVisible()))
{
string text = list.GetPropertyValue<string>("listText");
string style = list.GetPropertyValue<string>("listItemStyle");
<div class="col-md-2 text-center">
<div class="circle"><i class="@style"></i></div>
<p>@text</p>
</div>
}
}
答案 0 :(得分:1)
您可以尝试以下方法:
@{
var additionalClassForFirstItem = "col-md-offset-1";
foreach (IPublishedContent list in homeList.Where(x => x.IsVisible()))
{
string text = list.GetPropertyValue<string>("listText");
string style = list.GetPropertyValue<string>("listItemStyle");
<div class="col-md-2 text-center @{additionalClassForFirstItem}">
<div class="circle"><i class="@style"></i></div>
<p>@text</p>
</div>
if (!string.IsNullOrEmpty(additionalClassForFirstItem)) {
additionalClassForFirstItem = string.Empty;
}
}
}
或使用for
之类的整数变量迭代for (int i = 1, ..)
,并检查其是否为1