jinja2


Ⅰ. 插件描述

A very fast and expressive template engine.

Ⅱ. 基本信息

创建日期:  2010-10-17
使用用户:  9
Github星:  6879
插件作者:  The Pallets Projects

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'mitsuhiko/jinja2'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'mitsuhiko/jinja2'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'mitsuhiko/jinja2'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/mitsuhiko/jinja2

Ⅳ. 文档说明

Jinja

Jinja is a fast, expressive, extensible templating engine. Special
placeholders in the template allow writing code similar to Python

  1. Then the template is passed data to render the final document.

It includes:

  • Template inheritance and inclusion.
  • Define and import macros within templates.
  • HTML templates can use autoescaping to prevent XSS from untrusted
    user input.
  • A sandboxed environment can safely render untrusted templates.
  • AsyncIO support for generating templates and calling async
    functions.
  • I18N support with Babel.
  • Templates are compiled to optimized Python code just-in-time and
    cached, or can be compiled ahead-of-time.
  • Exceptions point to the correct line in templates to make debugging
    easier.
  • Extensible filters, tests, functions, and even syntax.

Jinja's philosophy is that while application logic belongs in Python if
possible, it shouldn't make the template designer's job difficult by
restricting functionality too much.

Installing

Install and update using pip_:

.. code-block:: text

$ pip install -U Jinja2

.. _pip: https://pip.pypa.io/en/stable/quickstart/

In A Nutshell

.. code-block:: jinja

{% extends "base.html" %}
{% block title %}Members{% endblock %}
{% block content %}
  <ul>
  {% for user in users %}
    <li><a target="_blank" rel="nofollow" href="{{ user.url }}">{{ user.username }}</a></li>
  {% endfor %}
  </ul>
{% endblock %}

Links

添加新评论