velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Christian <si...@cpd.co.uk>
Subject Re: iterator for substitution variables in template?
Date Wed, 18 Sep 2002 09:59:04 GMT
Martin,

To the best of my knowledge, Velocity doesn't maintain a list in quite 
the way you're envisaging. When the template is parsed, an AST tree is 
built which represents it.

There's no current functionality to 'list' out the contents of this 
tree, but I believe you could add something which traverses it to 
produce a list of references.

All told, if you really want to do something like this, you'll be better 
off with some kind of 'pull' model. You won't have to go to the trouble 
of pre-processing the template, just provide the data as and when it's 
required. There's a few ways you could implement this, the obvious ones 
being to either create a tool for the context which retrieves the data 
as it's requested, or to extend the VelocityContext to do similar.

- simon
	


Martin van Niekerk wrote:
> I have considered placing all potential values into the context, but
> unfortunately in my case it would not be very efficient. At some point the
> Velocity engine has to have access to such a list to perform the merge. My
> question is whether this functionality is surfaced or whether a person will
> have to change Velocity code to get at it.
> 
> Thanks
> Martin
> 
> 
> ----- Original Message -----
> From: "Simon Christian" <simon@cpd.co.uk>
> To: "Velocity Users List" <velocity-user@jakarta.apache.org>
> Sent: Wednesday, September 18, 2002 10:25 AM
> Subject: Re: iterator for substitution variables in template?
> 
> 
> 
>>That seems a bit like putting the cart before the horse. Surely it would
>>be easier, and probably more efficient, to put all potential values into
>>the context?
>>
>>- simon
>>
>>Martin van Niekerk wrote:
>>
>>>Hi there,
>>>
>>>I must apologise, I did not state my problem very clearly. Let me try
>>
> and
> 
>>>explain it using this example:
>>>
>>>If this were my template:
>>><HTML>
>>><BODY>
>>>Hello $name
>>><table>
>>>   <tr>
>>>     <td>
>>>       $message
>>>     </td>
>>>   </tr>
>>>   <tr>
>>>     <td>
>>>       $info
>>>     </td>
>>>   </tr>
>>></table>
>>></HTML>
>>>
>>>Is there any way I could get a list of the references in the template
>>>itself,
>>>in other words a something that would return the names of the references
>>
> as
> 
>>>follows:
>>>$name
>>>$message
>>>$info
>>>
>>>The idea is to populate my context dynamically with values, without
>>
> knowing
> 
>>>beforehand which references the template contains.
>>>
>>>Regards
>>>Martin
>>>
>>>
>>>----- Original Message -----
>>>From: <plynchnlm@netscape.net>
>>>To: ""Velocity Users List"" <velocity-user@jakarta.apache.org>
>>>Sent: Tuesday, September 17, 2002 9:53 PM
>>>Subject: RE: iterator for substitution variables in template?
>>>
>>>
>>>
>>>
>>>>I haven't tried this, but I think that if you put the context itself
>>>>into the context, you could use VelocityContext.internalGetKeys()
>>>>to get an array of the keys in the context.
>>>>
>>>>"Martin van Niekerk" <martin@realsystems.co.za> wrote:
>>>>
>>>>
>>>>
>>>>>Hi there!
>>>>>
>>>>>I'm not sure whether this question has been raised before, but is it
>>>>
>>>possible to get some sort of iterator for the list substitution
>>
> variables in
> 
>>>a template?
>>>
>>>
>>>>>Regards
>>>>>Martin
>>>>>
>>>>
>>>>
>>>>--
>>>>Paul Lynch
>>>>Aquilent, Inc.
>>>>National Library of Medicine
>>>>
>>>>
>>>
>>
>>--
>>To unsubscribe, e-mail:
> 
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> 
>>For additional commands, e-mail:
> 
> <mailto:velocity-user-help@jakarta.apache.org>
> 
> 
> 


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message