Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-885

希望 Velocity-tools-layout 能够增加 #block()、#super() 模板指令

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: Engine
    • Labels:
      None

      Description

      我在使用 Python 模板引擎 Jinja2(http://jinja.pocoo.org/)时,发现 Jinja2 的 *

      {% block title %} Default title {% endblock %}* 和 {{ super() }} 语法特性在 Layout 继承时非常有用,例如:
      default-layout.html
      
      

      <head>
      <title>{% block title %}

      Default title

      {% endblock %}</title>
      {% block head %}
      <link rel="stylesheet" href="style.css"/>
      {% endblock %}

      </head>
      <body>

      {% block content %} {% endblock %}
      </body>
      
      


      child.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 %}
      这种特性在 *局部大块内容进行复用/替换* 时非常有用,能提高 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>
      

      child.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>
      ...
      

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

      祝愿 Velocity 越来越好!

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              yswang Wang yongshan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: