I am looking to use new Templates to replace some stuff that uses Genshi (python) for complex XML templates. In Genshi, you can define partials exposed as methods, allowing variables to be passed in and dynamically select child partials.

Essentially the argument for one partial was used within the partial to inject another partial. Suggestions on how best to achieve this with ServiceStack? Looks like it could probably be done with partials if each partial was a separate file, which will get to be a bit overkill if say I want to have xml-based colour injected with dozens of colour presets.

In trials for this approach, I see that partials cannot specify arguments (ie: default values in page header), but I can pass a value into a partial and use it to inject a global _layout variable, which does help some aspects.

Coding each py:def as a filter might do the trick too, but I can't compile them, would need to be template-file based. Perhaps a notation to define filters within partials? Or named partials?

Curious to get your take on it.thanks!

ps: need to add a new topic category dropdown item for ServiceStack.Templates.

mythz
—
2017-09-29T19:29:14Z —
#2

For creating reusable code, Templates only supports partials and filters. Each partial does need to be in a separate file but they're not expensive at runtime as they're parsed, cached and evaluated in memory.

If you're going to use a filter you'll want to return IRawString, e.g. return xml.ToRawString(); so the XML response isn't encoded.

sirthomas
—
2017-09-29T20:21:28Z —
#3

ok, follow-up:

a) any way to specify argument in partials preamble (<!-- arg: 1 -->)b) would there be a way to extend Templates to allow dynamic filtersc) a way to inject partial args into the resolution of next partial? {{ 'partials/{{arg1}}' | partials }} or something like that?

For (c) I might need to create my own find filter to concate variables perhaps..