Speed: how to analyze / analyze "Directives / Content" stored in a variable?

I have a problem that seems pretty trivial, but I could not solve it. In my Velocity-Templates, I have a variable $contentFormDbpopulated with contents from the database (in the MVC application controller). This variable will contain not only literals, but also other Velocity directives (for example " #set($test = "test) $test", see the example below).

If I use $contentFromDBin my templates, Velocity prints the contents in my template as a "Literary Path". For example, if a variable $contentFromDBcontains a string " #set($test = "test) $test"(this was set in the controller), I will embed literal output #set($test = "test) $testin my speed template, not just that test.

I need something like a directive #parse()so that I can specify my variable $contentFromDB, and then it will evaluate the variable. #parse($contentFormDb)But #parse()it only accepts files that need to be evaluated / analyzed.

Maybe I missed something completely here ... But how to solve this problem, it seems to me that this is a standard use case containing content from the database, which then also needs to be evaluated in the template ...

Many thanks! Yang

+3
source share
2 answers

The #evaluate directive looks as if it will do what you want.

+3
source

you can register Velocimacros via #parse ()

This is made possible in Velocity 1.6.

0
source

Source: https://habr.com/ru/post/1734375/


All Articles