I found one way to do conditional markup is to do things like
{{ `<p>here is my markup</p>` | endIf(false) }}
That’ll short circuit the output and NOT do the markup. However, in more advanced cases, I need to exclude huge blocks of code. And sometimes even nested.
if(a)
{
some stuff
if(b)
{
some more stuff
}
}
Short of creating an insane amount of partials to make life easier, or using server-side C# templates where I can do the complex conditions (just as “not ideal” as lots of partials) what options do I have?
You can use partials for large blocks of texts with the existing versions of ServiceStack Templates, but if you upgrade to v5.1.1 on MyGet you can use the new Handlebars like support for if blocks, see existing tests for examples on usage.
Maybe I spoke too soon. I’m on 5.1.1 and still getting errors.
Example in index.html:
{{#if forSelection }}
Hello World!
{{/if}}
Exception:
ArgumentException: Invalid Syntax: expected start of identifier but was '#'
at ServiceStack.Templates.JsTokenUtils.ParseIdentifier(StringSegment literal, JsToken& token)
at ServiceStack.Templates.JsTokenUtils.ParseJsToken(StringSegment literal, JsToken& token, Boolean filterExpression)
at ServiceStack.Templates.JsExpressionUtils.ParseJsExpression(StringSegment literal, JsToken& token, Boolean filterExpression)
at ServiceStack.Templates.TemplatePageUtils.ParseTemplatePage(StringSegment text)
at ServiceStack.Templates.TemplatePage.Load()
at ServiceStack.Templates.TemplatePage.Init()
at ServiceStack.Templates.PageResult.Init()
at ServiceStack.Templates.PageResult.WriteToAsyncInternal(Stream outputStream, CancellationToken token)
at ServiceStack.Templates.PageResult.WriteToAsync(Stream responseStream, CancellationToken token)
at ServiceStack.TemplatePageHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)