String_if_invalid django or ninja template: custom renderer in selected html string

i'm looking for a solution to selectively not replace missing variables/replace by whatever in django:

I have a text, defined by a user, where he can insert variables {{model.myvar}}. In the backend, i render the text and the context to return a text which can be then modified if necessary.

So far so good...

For UX reasons, the variables can be entered at different times, and the text be generated at any time...So if all the var are not entered, there will be empty strings...

What i'm looking for is a way to get the free text with variables, and "generate" it as often as wanted ! So the text is sent to the backend, if the corresponding var is in the context => var is replaced ! but if there is not: return {{myvar}}. Then the txt can be re-generated later with appropriate information !

I deeply searched for a solution with django template and jinja. Indeed i explored "string_if_invalid" for django: but apply in all the app and can create problems. I'm looking for a custom solution which i can apply selectively in selected parts of my codes...

-Is it possible ? -How...?!

Thanks for your help !

Вернуться на верх