velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Huy Do" <...@tramada.com.au>
Subject RE: Whitespace, redux
Date Sun, 14 Apr 2002 22:53:18 GMT
This is starting to look a bit like

<?
  if ($option1) {
    $a = "hello"
  } else {
    $a = "goodbye"
  }
  echo("$a")
?>

and replace the <? with <% (don't mind the syntax) and look what we have.
Hope we're not going backwards now :-)

Huy

> -----Original Message-----
> From: Joaquim Carvalho [mailto:jrc@bookmarc.pt]
> Sent: Saturday, 13 April 2002 7:36 PM
> To: Velocity Users List
> Subject: Re: Whitespace, redux
>
>
>
> I have worked a long time ago in a templating language for web apps used
> in house for over 5 years.
>
> We had a similar whitespace problem (control flow directives created
> zones on the templates that produced undesired white space on the
> output).
>
> The solution we found was to add two whitespace related directives,
> "output" and "echo", that in Velocity would look something like this:
>
> 1. "output" switches output on and off (this applies to ALL output from
> the template to the output stream)
>
> #output("off") ## from now on there is no output from the template but
> the enclosed directives still are executed
> #if ($option1)
>     #set( $a = "hello")
> #else
>     #set($a = "goodbye")
> #end
> #output("on") ## restoring output
> $a>
>
> 2.After a #output("off") text could be forced to the output stream by
> using #echo:
>
> #output("off")
> #if ($option1)
>     #echo("hello")
> #else
>     #echo("goodbye")
> #end
> #output("on") ## restoring output
>
> 3. In macros and #parsed templates it is necessary to save and restore
> the previous output status so that other templates can safely use code
> in other files:
>
>
> $macro ( testOption, $option1)
>
> #output("hold") ## Sames as "off" but the current output state is
> remembered
> #if ($option1)
>     #set( $a = "hello")
> #else
>     #set($a = "goodbye")
> #end
> #output("restore") ## restoring output to previous status
> #end
>
>
>
> this has dealt with our whitespace handling problems for good. When
> writing sequences of directives, specially involving control structures
> that need to be indented for readability we just backet that part of the
> template with #output("off") #output("on") with an ocasional #echo
> inside if something needs to go out the stream.
>
> This also is nice for Velocity usage just as  aruntime scripting
> language not related to any type of outputing. We are using Velocity
> right now in such a setting: a bibliographic application needs to do
> some manipulation of library records according to transformation rules
> that are defined at runtime. By adding specially designed objects to the
> context we can use velocity as the rule language and templates just
> specify how an object is transformed into another one. The output from
> the template is irrelevant, so we could just as well avoida its
> production.
>
> As far as velocity goes I think such a solution would be backwards
> compatible; an implicit #output("on") is assumed for evey template (but
> not for the parsed ones).
>
> I think even if a template using #output and #echo would find itself
> being rendered by an older version of Velocity it would still work, I
> think, because #output and #echo would just be ignored (although of
> course the ouput would not be quite the desired one).
>
> This is not a request for modification, just a contribution to the
> discussion.
>
> Joaquim
>
>
> --
> 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