logo       

Re: parsing variable name in a velocity template: msg#00116

jakarta.velocity.user

Subject: Re: parsing variable name in a velocity template

Unless you want to be a mind reader, I'd ask the user to tell you their
template variable names that will feed into the template. Otherwise, tell
the user they can't have the format $something or ${something} in their
template without referring to a template variable. At this point, you
really aren't using Velocity at all.

Perhaps others could address whether the evaluate method with an empty
context would report references not found, which might give a good clue
for what Velocity recognizes as a reference in a template.

A text editor would have a pretty complicated job trying to determine
reference variables that should appear in the context and those that are
created by the template itself in #set and #foreach. And even then there
will probably be exceptions where the program won't interpret the same as
the user expects.

The MVC model assumes that the programmer will know what pieces of
information the designer wants to pass from the knowledge base to the
template. I think it's reasonable to ask your users what pieces of
information the user wants to send to their template. That avoids any
possible confusion from some outside program that is going to simulate
what context variables are expected. It will also provide more
clarity and flexibility for the user.

Barbara Baughman
X2157

On Tue, 20 May 2003, Normand Gagnon wrote:

> I understand your solution, but it is no what I mean.
>
> I was a *little bit* unclear about my problem,
>
> In fact, I don't want to read template variable from the context, but
> really from the template itself. So, how I do that?
>
> I need to create a html form that when submited, will be used to fill a
> context to generate another velocity template (the target template). So my
> html form need to include an input field for each variables contained in
> the target template. But, my problem is that i don't know in advance all
> variable names of the target template to create the appropriate html form
> because the target template is also submited by the user and it could be
> anything.
>
> So, if the user submit a template that contains a variable $foobar, I need
> to create dynamically a html form with an input field named "foobar".
>
> See my problem?
>
>
>
> At 03:07 PM 20/05/2003 -0500, Barbara Baughman wrote:
> >Put the Velocity context in the Velocity context. Then use the getKeys
> >method to get an array of all the context keys. Check the javadoc for
> >this at http://jakarta.apache.org/velocity/api/index.html.
> >
> >It is possible to have $something in a template without it referring to
> >any context field, so regex won't work in all cases.
> >
> >Barbara Baughman
> >X2157
> >
> >On Tue, 20 May 2003, Normand Gagnon wrote:
> >
> > > Hi,
> > >
> > > Is there a way to know the names of all templates variable (I.E:
> > > $variableName or ${variableName} ) used in a template? I want to
> > create a
> > > HTML form that will let the user fill-in the velocity context but key
> > names
> > > will vary depending on the velocity template selected by the user.
> > >
> > > The only way i'm thinking now, is using a Regex engine.
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx
> > > For additional commands, e-mail: velocity-user-help@xxxxxxxxxxxxxxxxxx
> > >
> > >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx
> >For additional commands, e-mail: velocity-user-help@xxxxxxxxxxxxxxxxxx
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx
> For additional commands, e-mail: velocity-user-help@xxxxxxxxxxxxxxxxxx
>
>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise