添加Jinjae
lektor-expression-type的Python项目详细描述
Lektor表达式类型插件
将jinja求值的类型expression
和format_expression
添加到
Lektor。在
它们允许定义值为Jinja2的数据模型字段 表达。在
类型
expression
和format_expression
类型都由
jinja模板引擎。在
expression
expression
类型被计算为Jinja2表达式。在
此类型的示例值可能是:
this.children.order_by('-pub_date').limit(4)
这将计算为Lektor Query实例。在
format_expression
format_expression
类型被计算为Jinja2模板。它
将始终计算为字符串。在
此类型的示例值可能是:
^{pr2}$安装
从命令行将lektor表达式类型添加到项目:
lektor plugins add lektor-expression-type
有关详细信息,请参见the Lektor plugin documentation。在
激励榜样
假设您想为页面创建一个Index数据模型
显示你网站上其他页面的列表。
你可以创建一个这样的模型定义(也许,
models/index.ini
):
[model]name=Index Pagelabel=Index: {{ this.title}}[fields.title]label=Titletype=string[fields.items]label=Itemstype=expressiondescription=Pages to list on this page
在使用此模型的特定索引页中,可以设置
items
字段到
site.get('/projects').filter(F.tag == 'interesting')
,
然后在页面模板中(例如在templates/index.html
)中可以
引用items
字段(例如{% for page in this.items %}
)
确定要在页面上显示的页面。在
作者
杰夫·戴里基dairiki@dairiki.org
- 项目
标签: