我如何传递“列表” Umbraco 宏的参数?
我有一个 Umbraco 宏,我想向其传递一个“列表”参数,即我有多个元素正在使用 XSLT 进行转换,并且我想以“特殊”方式转换其中一些元素。
理想情况下,我想尝试这样的事情:
<umbraco:Macro Alias="DoStuff" runat="server">
<styleThisSpecially>NameOfElement1</styleThisSpecially>
<styleThisSpecially>NameOfElement2</styleThisSpecially>
</umbraco:Macro>
不幸的是,这似乎不起作用——“styleThisSpecially”元素未被识别。
我能想到的解决方法是:
- 传递“styleThisSpecially1”、“styleThisSpecially2”、“styleThisSpecially3”等参数,...
- 将我的参数作为逗号分隔列表传递,如“styleThisSpecially='val1,val2,val3'”
...但这些选项似乎都不是很“整洁”。我尝试在 umbraco:Macro 元素上使用多个“styleThisSpecially”属性,但这导致了错误(“标签包含重复的“expandBox”属性”)。
有没有一种干净整洁的方法来做到这一点?
I have an Umbraco macro that I'd like to pass a "list" argument to — i.e. I have multiple elements that I'm transforming with XSLT, and I'd like to transform some of them in a "special" way.
Ideally I'd like to try something like this:
<umbraco:Macro Alias="DoStuff" runat="server">
<styleThisSpecially>NameOfElement1</styleThisSpecially>
<styleThisSpecially>NameOfElement2</styleThisSpecially>
</umbraco:Macro>
Unfortunately that doesn't seem to work — the "styleThisSpecially" elements are not recognised.
Workarounds I can think of are:
- passing through arguments like "styleThisSpecially1", "styleThisSpecially2", "styleThisSpecially3", ...
- passing through my argument as a comma separated list like "styleThisSpecially='val1,val2,val3'"
...but neither of these options seem very "neat". I tried using multiple "styleThisSpecially" attributes on the umbraco:Macro element, but that caused an error ("the tag contains duplicate 'expandBox' attributes").
Is there a clean and tidy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,您将从“点 X”开始并计算出所有元素,并且您希望将它们作为列表全部传递给宏。
可能更简洁的解决方案是:
1. 让页面不仅找到元素,还迭代这些元素并将它们一次一个地传递给宏以进行“渲染/处理/其他”
2. 将“点X”传递给宏,让宏计算出元素是什么?
并没有真正回答是否可以将元素列表传递给宏的问题,但我认为也许(当然,如果您使用 XSLT)这很少是您想要做的事情。
If I understand you correctly you're starting at "point X" and working out all the elements and you want to pass them all to the macro as a list.
Probably a neater solution is either:
1. Let the page not only find the elements, but also iterate these and pass them one at a time to the macro for "rendering/processing/whatever"
2. Pass "point X" to the macro and let the macro work out what the elements are?
Doesn't really answer the question of whether you can pass a list of elements to a macro, but I think perhaps (certainly if you're working in XSLT) this is rarely something you'd want to do.