You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Guido Deinhammer (JIRA)" <de...@velocity.apache.org> on 2007/06/22 08:08:26 UTC

[jira] Created: (VELOCITY-558) Allow macros that act as blockDirectives

Allow macros that act as blockDirectives
----------------------------------------

                 Key: VELOCITY-558
                 URL: https://issues.apache.org/jira/browse/VELOCITY-558
             Project: Velocity
          Issue Type: Improvement
          Components: Engine
    Affects Versions: 1.5
         Environment: Windows
            Reporter: Guido Deinhammer
            Priority: Minor


Currently migrating a web project from Oracle's proprietary UIX to Velocity, I found the limitation that macros are always line directives and cannot ave content somewhat limiting.

I would suggest the following improvement or addition to the macro functionality.

You should be able to define a blockMacro - maybe with a syntax like this:

#blockmacro(section $title $open)
<table><th><td>$title</td></th>
#if($open)
  #body
#end
</table>
#end

Where #body would render the body of the macro call. The macro call could look like this:

#section("My Collapsible Section", true)
<tr><td>sectionContent</td></tr>
#end

This allows the macro to render the content only under a certain condition, or it would allow the macro to render the content multiple times. I think this would a lot of flexibilty to macros - it might be an enhancement worth considering for the Summer of Code Google project.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


Re: [jira] Created: (VELOCITY-558) Allow macros that act as blockDirectives

Posted by Jonathan Revusky <re...@gmail.com>.
Guido Deinhammer (JIRA) wrote:
> Allow macros that act as blockDirectives
> ----------------------------------------
> 
>                  Key: VELOCITY-558
>                  URL: https://issues.apache.org/jira/browse/VELOCITY-558
>              Project: Velocity
>           Issue Type: Improvement
>           Components: Engine
>     Affects Versions: 1.5
>          Environment: Windows
>             Reporter: Guido Deinhammer
>             Priority: Minor
> 
> 
> Currently migrating a web project from Oracle's proprietary UIX to Velocity, I found the limitation that macros are always line directives and cannot ave content somewhat limiting.
> 
> I would suggest the following improvement or addition to the macro functionality.
> 
> You should be able to define a blockMacro - maybe with a syntax like this:
> 
> #blockmacro(section $title $open)
> <table><th><td>$title</td></th>
> #if($open)
>   #body
> #end
> </table>
> #end
> 
> Where #body would render the body of the macro call. The macro call could look like this:
> 
> #section("My Collapsible Section", true)
> <tr><td>sectionContent</td></tr>
> #end
> 
> This allows the macro to render the content only under a certain condition, or it would allow the macro to render the content multiple times. I think this would a lot of flexibilty to macros - it might be an enhancement worth considering for the Summer of Code Google project.

IMO, at this stage of history, the above-requested feature should 
actually be considered part of the basic feature set of any template 
engine (particularly for use on the web). It is very hard to use macros 
to encapsulate commonly used snippets of HTML coding without this.

FreeMarker has had this for nearly 5 years. I implemented this in code 
in mid or maybe late 2002, IIRC. Rather than the #body directive that 
Guido proposes, FreeMarker uses <#nested>. Same difference.

See:

http://freemarker.org/docs/dgui_misc_userdefdir.html

or

http://freemarker.org/docs/ref_directive_macro.html

I was going to drop an email to Guido Deinhammer but couldn't find his 
email address.

I think it proper to reply here, since many people might need this, it 
being such a basic thing.

And so as to avoid more such informative emails, another extremely basic 
deficiency in Velocity's macro system, that you can't load macros from 
another template using the #parse directive -- you can do this in 
FreeMarker, of course. Though, unlike the above feature of macros with 
nested blocks, which I implemented in code in 2002, the ability to 
dynamically #include templates with other macros in them has been in 
FreeMarker since well before I was active in the project, like 1999 or 
so -- actually, amazingly, before the Velocity project even existed. 
This is also a very basic capability without which it is near-impossible 
to organize one's templates according to the DRY (don't repeat yourself) 
principle.

I think the above could be useful information for people.

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org/






> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Resolved: (VELOCITY-558) Allow macros that act as blockDirectives

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-558?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Bubna resolved VELOCITY-558.
-----------------------------------

    Resolution: Duplicate

Yep.  Since VELOCITY-583 has a patch, let's favor that and close this.

> Allow macros that act as blockDirectives
> ----------------------------------------
>
>                 Key: VELOCITY-558
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-558
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.5
>         Environment: Windows
>            Reporter: Guido Deinhammer
>            Priority: Minor
>
> Currently migrating a web project from Oracle's proprietary UIX to Velocity, I found the limitation that macros are always line directives and cannot ave content somewhat limiting.
> I would suggest the following improvement or addition to the macro functionality.
> You should be able to define a blockMacro - maybe with a syntax like this:
> #blockmacro(section $title $open)
> <table><th><td>$title</td></th>
> #if($open)
>   #body
> #end
> </table>
> #end
> Where #body would render the body of the macro call. The macro call could look like this:
> #section("My Collapsible Section", true)
> <tr><td>sectionContent</td></tr>
> #end
> This allows the macro to render the content only under a certain condition, or it would allow the macro to render the content multiple times. I think this would a lot of flexibilty to macros - it might be an enhancement worth considering for the Summer of Code Google project.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-558) Allow macros that act as blockDirectives

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12507140 ] 

Will Glass-Husain commented on VELOCITY-558:
--------------------------------------------

Nice idea -- thanks for suggesting it. (and good example).

I think something similar is already in JIRA but couldn't find it.  Somewhat related to VELOCITY-174.

> Allow macros that act as blockDirectives
> ----------------------------------------
>
>                 Key: VELOCITY-558
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-558
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.5
>         Environment: Windows
>            Reporter: Guido Deinhammer
>            Priority: Minor
>
> Currently migrating a web project from Oracle's proprietary UIX to Velocity, I found the limitation that macros are always line directives and cannot ave content somewhat limiting.
> I would suggest the following improvement or addition to the macro functionality.
> You should be able to define a blockMacro - maybe with a syntax like this:
> #blockmacro(section $title $open)
> <table><th><td>$title</td></th>
> #if($open)
>   #body
> #end
> </table>
> #end
> Where #body would render the body of the macro call. The macro call could look like this:
> #section("My Collapsible Section", true)
> <tr><td>sectionContent</td></tr>
> #end
> This allows the macro to render the content only under a certain condition, or it would allow the macro to render the content multiple times. I think this would a lot of flexibilty to macros - it might be an enhancement worth considering for the Summer of Code Google project.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-558) Allow macros that act as blockDirectives

Posted by "Jarkko Viinamäki (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12622998#action_12622998 ] 

Jarkko Viinamäki commented on VELOCITY-558:
-------------------------------------------

This looks a lot like VELOCITY-583

> Allow macros that act as blockDirectives
> ----------------------------------------
>
>                 Key: VELOCITY-558
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-558
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.5
>         Environment: Windows
>            Reporter: Guido Deinhammer
>            Priority: Minor
>
> Currently migrating a web project from Oracle's proprietary UIX to Velocity, I found the limitation that macros are always line directives and cannot ave content somewhat limiting.
> I would suggest the following improvement or addition to the macro functionality.
> You should be able to define a blockMacro - maybe with a syntax like this:
> #blockmacro(section $title $open)
> <table><th><td>$title</td></th>
> #if($open)
>   #body
> #end
> </table>
> #end
> Where #body would render the body of the macro call. The macro call could look like this:
> #section("My Collapsible Section", true)
> <tr><td>sectionContent</td></tr>
> #end
> This allows the macro to render the content only under a certain condition, or it would allow the macro to render the content multiple times. I think this would a lot of flexibilty to macros - it might be an enhancement worth considering for the Summer of Code Google project.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org