[ 
https://issues.apache.org/jira/browse/VELOCITY-885?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Wang yongshan updated VELOCITY-885:
-----------------------------------
    Description: 
我在使用 Python 模板引擎 Jinja2(http://jinja.pocoo.org/)时,发现 Jinja2 的  *{% block title 
%} Default title {% endblock %}* 和  *{{ super() }}* 语法特性在 Layout 继承时非常有用,例如:
*default-layout.html*
{code:html}
<head>
  <title>{% block title %} Default title {% endblock %}</title>
  {% block head %}
    <link rel="stylesheet" href="style.css"/>
  {% endblock %}
</head>
<body>
{% block content %} {% endblock %}
</body>
{code}

*child.html*
{code:html}
{% extends "default-layout.html" %}
{% block title %}User Manager{% endblock %}
{% block head %}
   {{ super() }}
   <style type="text/css">
   .important {color: #cc0000; font-weight:bold;}
   </style>
{% endblock %}
{% block content %}
<h2>User Manager</h2>
...
{% endblock %}
{code}

这种特性在 *局部大块内容进行复用/替换* 时非常有用,能提高 Web 页面的开发效率和减少一定的代码量。

因此,我在 Velocity-1.7.x 中进行了修改,增加了: *#block()  #end* 、*#override() #end* 和 
*#super()* 指令,用法如下:
*default-layout.html*
{code:html}
<head>
  <title>#block("title") Default title #end</title>
  #block("head")
    <link rel="stylesheet" href="style.css"/>
  #end
</head>
<body>
$!{ screen_content }
</body>
{code}

*child.html*
{code:html}
#override("title") User Manager #end
#override("head") 
   #super()
   <style type="text/css">
   .important {color: #cc0000; font-weight:bold;}
   </style>
#end

<h2>User Manager</h2>
...
{code}

希望 Velocity-2.x 后面也能够增加类似 Jinja2 的 block、super 等指令。

祝愿 Velocity 越来越好!


  was:
我在使用 Python 模板引擎 Jinja2(http://jinja.pocoo.org/)时,发现 Jinja2 的  *{% block title 
%} Default title {% endblock %} *和  *{{ super() }}* 语法特性在 Layout 继承时非常有用,例如:
*default-layout.html*
{code:html}
<head>
  <title>{% block title %} Default title {% endblock %}</title>
  {% block head %}
    <link rel="stylesheet" href="style.css"/>
  {% endblock %}
</head>
<body>
{% block content %} {% endblock %}
</body>
{code}

*child.html*
{code:html}
{% extends "default-layout.html" %}
{% block title %}User Manager{% endblock %}
{% block head %}
   {{ super() }}
   <style type="text/css">
   .important {color: #cc0000; font-weight:bold;}
   </style>
{% endblock %}
{% block content %}
<h2>User Manager</h2>
...
{% endblock %}
{code}

这种特性在 *局部大块内容进行复用/替换* 时非常有用,能提高 Web 页面的开发效率和减少一定的代码量。

因此,我在 Velocity-1.7.x 中进行了修改,增加了: *#block()  #end*、*#override() #end* 和 
*#super()* 指令,用法如下:
*default-layout.html*
{code:html}
<head>
  <title>#block("title") Default title #end</title>
  #block("head")
    <link rel="stylesheet" href="style.css"/>
  #end
</head>
<body>
$!{ screen_content }
</body>
{code}

*child.html*
{code:html}
#override("title") User Manager #end
#override("head") 
   #super()
   <style type="text/css">
   .important {color: #cc0000; font-weight:bold;}
   </style>
#end

<h2>User Manager</h2>
...
{code}

希望 Velocity-2.x 后面也能够增加类似 Jinja2 的 block、super 等指令。

祝愿 Velocity 越来越好!



> 希望 Velocity-tools-layout 能够增加 #block()、#super() 模板指令
> ----------------------------------------------------
>
>                 Key: VELOCITY-885
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-885
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>    Affects Versions: 2.1.x
>            Reporter: Wang yongshan
>            Priority: Minor
>             Fix For: 2.1.x
>
>
> 我在使用 Python 模板引擎 Jinja2(http://jinja.pocoo.org/)时,发现 Jinja2 的  *{% block 
> title %} Default title {% endblock %}* 和  *{{ super() }}* 语法特性在 Layout 
> 继承时非常有用,例如:
> *default-layout.html*
> {code:html}
> <head>
>   <title>{% block title %} Default title {% endblock %}</title>
>   {% block head %}
>     <link rel="stylesheet" href="style.css"/>
>   {% endblock %}
> </head>
> <body>
> {% block content %} {% endblock %}
> </body>
> {code}
> *child.html*
> {code:html}
> {% extends "default-layout.html" %}
> {% block title %}User Manager{% endblock %}
> {% block head %}
>    {{ super() }}
>    <style type="text/css">
>    .important {color: #cc0000; font-weight:bold;}
>    </style>
> {% endblock %}
> {% block content %}
> <h2>User Manager</h2>
> ...
> {% endblock %}
> {code}
> 这种特性在 *局部大块内容进行复用/替换* 时非常有用,能提高 Web 页面的开发效率和减少一定的代码量。
> 因此,我在 Velocity-1.7.x 中进行了修改,增加了: *#block()  #end* 、*#override() #end* 和 
> *#super()* 指令,用法如下:
> *default-layout.html*
> {code:html}
> <head>
>   <title>#block("title") Default title #end</title>
>   #block("head")
>     <link rel="stylesheet" href="style.css"/>
>   #end
> </head>
> <body>
> $!{ screen_content }
> </body>
> {code}
> *child.html*
> {code:html}
> #override("title") User Manager #end
> #override("head") 
>    #super()
>    <style type="text/css">
>    .important {color: #cc0000; font-weight:bold;}
>    </style>
> #end
> <h2>User Manager</h2>
> ...
> {code}
> 希望 Velocity-2.x 后面也能够增加类似 Jinja2 的 block、super 等指令。
> 祝愿 Velocity 越来越好!



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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

Reply via email to