Twig 是 快速 ,灵活 ,安全的PHP前端模版。
标记说明 :
concise 简洁
熟悉Twig
标记说明 :
- {{ ... }}: prints the content of a variable or the result of an expression;
输出内容变量或者是表达式的结果。
<li><a href="http://symfony.com/doc/{{ version }}/book/index.html">The Book</a></li>
- {% ... %}: controls the logic of the template; it is used for example to execute for loops and
逻辑控制或者是循环或者是IFELSE
{% if app.environment == 'dev' %}<div class="block-configure"><div class="illustration"><img src="{{ asset('bundles/acmedemo/images/welcome-configure.gif') }}" alt="Configure your application" /></div><a href="{{ path('_configurator_home') }}" class="sf-button sf-button-selected"><span class="border-l"><span class="border-r"><span class="btn-bg">Configure</span></span></span></a></div>{% endif %}
- {# ... #}: allows including comments inside templates.
twig注释部分,并不会展示在网页上。
装饰模版
{% extends "AcmeDemoBundle::layout.html.twig" %}{% block title "Hello " ~ name %}{% block content %}<h1>Hello {{ name }}!</h1>{% endblock %}{% set code = code(_self) %}
继承并重写content内容。
{% block %}
{% block head %}<link rel="icon" sizes="16x16" href="{{ asset('favicon.ico') }}" /><link rel="stylesheet" href="{{ asset('bundles/acmedemo/css/demo.css') }}" />{% endblock %}
利用asset引入CSS和img等外部资源。

本文介绍了Twig模版引擎的基本用法,包括变量输出、逻辑控制、循环和条件判断等核心特性,并展示了如何通过继承和重写来组织复杂的页面布局。

1345

被折叠的 条评论
为什么被折叠?



