开发者

Callbacks or simple arithmetic in StringTemplate

开发者 https://www.devze.com 2023-03-05 02:13 出处:网络
I\'d like to use something like this in StringTemplate - to call a function defined in the application that does the rendering, is that possible?

I'd like to use something like this in StringTemplate - to call a function defined in the application that does the rendering, is that possible?

<div> $renderArticle(article,width,padding)$ </div>

I could use a custom type/class just for this field but that seems a bit hacked togheter and not a real solution to the problem, and it wont allow me to pass in arguments as far as i know.

开发者_运维百科

I want this becuase i want to allow users to customize templates, for example: i know the how much width i have available for the article but i want the user to be able to specify padding so that i can generate optimal image thumbnails inside that template.

Or, if is it possible to use simple arithmetics, that would be another solution to the problem, something like this perhaps:

... width="$width-50$ ...

I have been looking all over for this and not found any information...

I'd rather use StringTemplate because the application already uses it, but i could switch to something else if it's more suitable, maybe i should take a look at NVelocity?


As I82Much says in his comment, StringTemplate doesn't support calculations.

One solution is to enrich your model with a new property whose value is pre-calculated as 'width-50'.

If you're looking for an alternative, and you're using .net 4.0, you can host the razor view engine and use it as your templating solution.

0

精彩评论

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

关注公众号