scriban / scriban

A fast, powerful, safe and lightweight scripting language and engine for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to delay the rendering of one or multiple {{EXPR}}

asgard-alliance opened this issue · comments

I'm trying to preparse a template except for a few "special" expressions for which I want a late binding if you will. I'm trying to generate multiple similar outputs except for a few variables:

  • Render template except few variables
  • Loop
  • Set late binding variables and finish render, save output
  • Repeat
  • End

Could you elaborate with a simple example of how that would work? Today, the rendering is delayed until we evaluate expressions, so it is happening already very late, at the moment things need to be rendered, so not sure how a delay would work.

It sounds like you are looking for multiple rendering passes, and in that case, you would have to handle it on your side: your 1st level template would emit a scriban like output that could be reparsed and rendered in a second phase.

I'm actually already doing multiple rendering passes (3) and it works great. However, in this case (I'm generating ZPL content via custom functions), I want to render everything except one expression that would look like this "{{SPECIAL}}" and then I want to iterate multiple times, change the value in the context for SPECIAL and render 100%, save output then continue iterating. I'm trying to avoid re-rendering from scratch every time.

I also tried with Escaping {%%%{ but it seems to render in 1 pass. I was expecting {%%%{ to become {%%{ then {%{ then nothing.

The goal is really to "protect" an expression until I'm ready to render it.

I also tried with Escaping {%%%{ but it seems to render in 1 pass. I was expecting {%%%{ to become {%%{ then {%{ then nothing.

It is an escape sequence, not a rendering action. {%%%{ helps to escape e.g {%%{.

The goal is really to "protect" an expression until I'm ready to render it.

So using multiple rendering passes is the way to go and you can for example define SPECIAL as "{{SPECIAL}}" until you want to render it on a last pass.