V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Kai
V2EX  ›  Go 编程语言

Django-syntax like template-engine for Go: pongo

  •  
  •   Kai · 2015-09-04 01:48:23 +08:00 · 899 次点击
    这是一个创建于 3171 天前的主题,其中的信息可能已经有所发展或是发生改变。

    pongo2, https://github.com/flosch/pongo2

    <html><head><title>Our admins and users</title></head>
    {# This is a short example to give you a quick overview of pongo2's syntax. #}
    
    {% macro user_details (user, is_admin=false ) %}
        <div class="user_item">
            <!-- Let's indicate a user's good karma -->
            <h2 {% if (user.karma >= 40 ) || (user.karma > calc_avg_karma (userlist )+5 ) %}
                class="karma-good"{% endif %}>
    
                <!-- This will call user.String () automatically if available: -->
                {{ user }}
            </h2>
    
            <!-- Will print a human-readable time duration like "3 weeks ago" -->
            <p>This user registered {{ user.register_date|naturaltime }}.</p>
    
            <!-- Let's allow the users to write down their biography using markdown;
                 we will only show the first 15 words as a preview -->
            <p>The user's biography:</p>
            <p>{{ user.biography|markdown|truncatewords_html:15 }}
                <a href="/user/{{ user.id }}/">read more</a></p>
    
            {% if is_admin %}<p>This user is an admin!</p>{% endif %}
        </div>
    {% endmacro %}
    
    <body>
        <!-- Make use of the macro defined above to avoid repetitive HTML code
             since we want to use the same code for admins AND members -->
    
        <h1>Our admins</h1>
        {% for admin in adminlist %}
            {{ user_details (admin, true ) }}
        {% endfor %}
    
        <h1>Our members</h1>
        {% for user in userlist %}
            {{ user_details (user ) }}
        {% endfor %}
    </body>
    </html>
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5089 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:59 · PVG 17:59 · LAX 02:59 · JFK 05:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.