我必须渲染一个或一个条件,但是,苗条的缩进和“没有明确的结束允许”的方式。缩进哎呀,如果“如果条件<a>其他<span>”slim
在这个简化的代码中,我想根据产品是否可用,将包含三个DIV的产品包装在A或SPAN中。
- if available?
a href=...
- else
span class="unavailable"
.currency = @product.currency
.price = @product.price
.description = @product.description
以上显然不会工作,因为产品没有A或跨度内的渲染,但在它旁边。
- if available?
a href=...
- else
span class="unavailable"
.currency = @product.currency
.price = @product.price
.description = @product.description
这种情况甚至更糟,因为苗条对待产品为“其他”一案的一部分,使旁边的SPAN,而不是产品都为A.
- if available?
a href=...
- else
span class="unavailable"
.currency = @product.currency
.price = @product.price
.description = @product.description
这里一切都很好的SPAN,但A仍然是空的,因为该产品被视为“其他”案件的一部分。现在
- if available?
a href=...
- else
span class="unavailable"
- end
.currency = @product.currency
.price = @product.price
.description = @product.description
,这可能是正确的,但苗条不允许明确的“结束”,因此会引发异常。
任何想法如何让这个工作? PS:也许苗条应该允许明确的“结束”像这样的边缘情况。
我gues您可以通过这种方式创建一个部分来保存产品,然后从条件的两边呈现相同的结果。所以,' - 如果有的话?一个href = ...(渲染产品) - 否则span class =“unavailable”(渲染产品)'希望你明白了,因为我似乎无法得到很好的评论格式。 :) –