[
http://issues.apache.org/jira/browse/VELOCITY-468?page=comments#action_12444056
]
Mojmir Hanes commented on VELOCITY-468:
---------------------------------------
Your code works, but it is called from Java, eg you define in Java code, which
templates you're processing
I'd like to instantiate in standalone Java application texen generator, fill
velocity context with necessary objects and start parsing control template, eg
Context context = new VelocityContext();
context.put("a","zz");
context.put("b","zz");
context.put("c","zz");
generator.parse("control.vm",context);
In control.vm I'm using many $generator.parse(...) calls
$generator.parse("top.vm", "main.html", "title" ,"Html title")
$generator.parse("left.vm", "main.html", "param1" ,"Value1")
$generator.parse("middle.vm", "main.html", "param2" ,"Value2")
This behaviour (calling templates from control.vm) is used in Apache Torque as
well (in fact I've copied this idea from Torque :-) )
I have one template which is processed two times. I need to process it
- first time with
param1 equal to value1 and
param2 equal to value2
- second time with
param1 equal to valueA and
param2 equal to valueB
So I need in control.vm something like (for first processing)
$generator.put("param1", "value1")
$generator.parse("common-template.vm", "page1.html", "param2" ,"value2")
and then (for second processing)
$generator.put("param1", "valueA)
$generator.parse("common-template.vm", "page2.html", "param2" ,"valueB")
I can't write here any Java code, because I'm in .vm (velocity template)
source, so your solution
doesn't work.
If controlContext field was protected, I could extend texen Generator and add
method
for putting object to context myself:
public void put (String objectID, Object object)
{
controlContext.put(objectID, object);
}
and then I'm fine with
$generator.put(...)
in my control.vm, but because it's private (and there is not setter method in
texen Generator) I don't have access to context.
Have you got my point ?
> Allowing putting objects into control context from VTL
> ------------------------------------------------------
>
> Key: VELOCITY-468
> URL: http://issues.apache.org/jira/browse/VELOCITY-468
> Project: Velocity
> Issue Type: Improvement
> Components: Texen
> Affects Versions: 1.4
> Reporter: Mojmir Hanes
> Priority: Minor
> Fix For: 1.6
>
> Attachments: Generator.java.diff
>
>
> I think it would be nice to allow putting objects into control context in
> VTL.
> The motivation is straightforward - in some cases you need to put more than
> one object into context before parsing particular template, so method
> org.apache.velocity.texen.parse(String inputTemplate, String outputFile,
> String objectID,Object object) doesn't match your need.
> What do you think ?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]