开发者

Spark View Engine, Override ${} behaviour

I was wondering if you guys could help me out. I've used the Spark view engine to create my own templating engine which eventually ends up creating an Excel file.

However I've encountered a problem. During this process I push the resultant spark output into an XmlDocument. This causes me problems with illegal characters being produced by spark. For example

<foo>
    <bar>${Model.Something}</bar>
</foo>

Gets parsed by Spark to produce

<foo>
    <bar>This < is a pr开发者_如何学Pythonoblem</bar>
</foo>

So I'm hoping there is someway I can overide the ${} so that I can deal with the illegal character.

Also please bear in mind that the resultant spark output is a string.

Any thoughts?

Thanks in advance


Had same situation, this is the workaround:

<!-- Use instead of built-in H() that only works in HTTP context (Html != null) -->
<macro name="H" html="string">${System.Web.HttpUtility.HtmlEncode(html)}</macro>

This way you don't need to change your views, you just redefine H() and the do ${H(Model.Something)} as usual.

You can also put this macro into the \Shared_global.spark so that it affects all views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜