Jinja2 on custom HTML template

I have an HTML in form_template.yaml

container:
  type: HtmlTemplate
  properties:...

What’s the best way to render it, using Jinja2, for example?
Or any other parameterized engine.

I need to programatically add slots surrounded by additional html

Is it possible to use __init__.py of the same page for this?
Is there any default way to archive this?

Thank you!

Regarding Jinja2, Jinja2 is available on the server. So you could use your template, server-side, to produce an HTML string, and return that from the server function.

There is no way to update form_template.yaml at run-time. Each instance of the form, however, can customize its HTML at run-time, as it is displayed in the user’s browser. You could update the HTML in the form class’s __init__ method.

Regarding slots, see Custom HTML Templates. In principle, you could add Anvil slots this way, but since those slots would exist only outside of the Anvil IDE, in the user’s browser, I’m not sure what this would gain you.

It’s not clear to me what “this” is, so I can’t really say. Perhaps a more concrete list of intended steps – what you would like to happen, and when – might help.

2 Likes

The Rich Text component has a facility to mix (restricted) html with slots that you can programmatically fill with components. That might be another option.

2 Likes

Thank you, that’s an interesting concept!

Thanks! Your advice was really helpful!