You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Michael Osipov (JIRA)" <ji...@apache.org> on 2017/11/02 11:34:00 UTC

[jira] [Updated] (VELOCITY-885) 希望 Velocity-tools-layout 能够增加 #block()、#super() 模板指令

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

Michael Osipov updated VELOCITY-885:
------------------------------------
    Affects Version/s:     (was: 2.1.x)
                       2.0

> 希望 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.0
>            Reporter: Wang yongshan
>            Priority: Minor
>
> 我在使用 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 {font-size:20px;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 {font-size:20px;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-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org