jacmoe / template-mthaml
一个PhileCMS插件,提供Mthaml(多目标HAML)模板解析器
1.0.8
2015-10-30 09:21 UTC
Requires
- mthaml/mthaml: ^1.7
- phile-cms/phile: >=1
- phile-cms/plugin-installer-plugin: >=1
README
这是一个PhileCMS插件,提供Mthaml(多目标HAML)模板解析器。
什么是MtHaml?
MtHaml是PHP实现的多语言HAML语言。
目前支持的目标是PHP和Twig,并且可以轻松添加新的目标。
此插件使用Twig目标,允许我们使用Twig标签(而不是Ruby标签)编写我们的模板。
安装
使用composer
composer require jacmoe/template-mthaml
下载
- 安装Phile
- 将此仓库克隆到plugins/jacmoe/templateMthaml
激活
安装插件后,您需要将以下行添加到您的config.php文件中
$config['plugins']['jacmoe\\templateMthaml'] = array('active' => true);
您需要关闭默认的Phile模板解析器
$config['plugins']['phile\\templateTwig'] = array('active' => false);
如何使用插件
安装后,此插件现在可以渲染主题目录中的任何haml文件。
模板扩展
您可以在插件配置中更改默认模板扩展名(.haml),但需要在每个模板文件的开头插入以下代码
{% haml %}
使用.haml文件时不需要此标签。
示例模板
在[plugin]/example
目录中有一个示例index.haml文件。
使用示例
%ul#users
- for user in users
%li.user
= user.name
Email: #{user.email}
%a(href=user.url) Home page
渲染
<ul id="users">
{% for user in users %}
<li class="user">
{{ user.name }}
Email: {{ user.email }}
<a href="{{ user.url }}">Home page</a>
</li>
{% endfor %}
</ul>
以下是一个示例模板
!!!
%html
%head
%meta(charset="#{ config.charset }")
%base(href="#{ base_url }")
%title
-if meta.title
=meta.title
=site_title
-if meta.description
%meta(name="description" content="#{ meta.description }")
-if meta.robots
%meta(name="robots" content="#{ meta.robots }")
%meta(property="og:type" content="article")
%meta(property="og:title" content="#{ current_page.title } | #{ site_title }")
%meta(property="og:description" content="#{ meta.description }")
%meta(property="og:url" content="#{ current_page.url }")
%meta(property="og:site_name" content="#{ site_title }")
%link(rel="stylesheet" href="#{ theme_url }/css/style.css")
%link(rel="stylesheet" href="#{ theme_url }/css/tomorrow-night.css")
%body
%header#header
.inner.clearfix
%h1
%a(href="#{ base_url }") = site_title
%ul.nav
-for page in pages
%li
%a(href="#{ page.url }") = page.title
%section#content
.inner
=content
%footer#footer
.inner
%a(href="https://github.com/PhileCMS/Phile") Phile
was made by
%a(href="https://github.com/PhileCMS") The PhileCMS Community
%script(src="#{ theme_url }/js/highlight.js")
:javascript
hljs.initHighlightingOnLoad();
比常规twig模板更简洁,对吧?
技巧
虽然主模板文件必须使用MtHaml(.haml)格式,但您可以包含类似这样的‘旧’ .html部分模板
- include 'header.html'
任何Twig标记都会由引擎处理,这意味着您可以逐步升级您的主题以使用MtHaml。
如果您想要一个完整的示例,请查看此处的haml模板文件:Jacmoes Cyber Soapbox Mercurial Repository