Velocity and macros embedded in content

A

Arvind

We are researching on usage of velocity at our place....we havesetup
velocity with templates being loaded from databases, setup for using
the macros etc.

If the 'rendered' content has VTL code in it, I am curious, as to
how/whether we can support 'another pass' of velocity, ..as in,
user-generated content using system defined velocity macros.

hypothetical example....


##define a macro to 'bold' the output text in bold.vm
#macro (bolder $text)
<b>$text</b>
#end

actual template.....
Template (foo.vm)

#parse ('bold.vm')

<html>

#bolder ('welcome john doe')

#foreach
<!--print some list of items and items themselves contain #bolder
(sometext) -->
#end
</html>

When the velocity engine is done with its work, #bolder (sometext) does
not get evaluated and it gets printed out as-is

This requirement is like the usage of macros in confluence (atlassian)
etc - just curious whether there are users who have used velocity for
this purpose. If there are - any best practises/things to watch out for
?

Are there other ways of handling such requirements ?

Thanks for your time.
 
J

Jean-Francois Briere

You cannot use #parse to do that.
You must define bold.vm in the velocimacro.library properties before
executing the Velocity engine.
You could also insert the velocimacro directly into the template
foo.vm.

Regards
 
A

Arvind

Jean-Francois Briere said:
You cannot use #parse to do that.
You must define bold.vm in the velocimacro.library properties before
executing the Velocity engine.
You could also insert the velocimacro directly into the template
foo.vm.

Thanks - I think i failed to add that - #bolder ('welcome john doe')
works perfectly ok in the example specified above.

What fails however is as follows...let us consider the example of a
vector of colors am printing out - and the colors can be
entered/maintained by the user....

i.e. the user maintains, red, blue, #bolder ('green'), black, #bolder
('yellow') - expecting that the list when printed, would contain the
text green and yellow in bold..(as per the macro behavior)

When velocity engine runs thru the list....it prints them as specified
by the user....however, we would rather that, velocity engine, wait for
the output, which would now contain, some more velocity templates/macro
references and do one-more pass...

Hope i made myself clear ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top