Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Velocity and macros embedded in content

1 view
Skip to first unread message

Arvind

unread,
Apr 26, 2006, 4:14:45 PM4/26/06
to
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.

--
Arvind

Jean-Francois Briere

unread,
Apr 26, 2006, 5:43:52 PM4/26/06
to
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

Arvind

unread,
Apr 26, 2006, 6:35:30 PM4/26/06
to

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 ?

--
Arvind

0 new messages