Symfony - view

来源:互联网 发布:linux网络编程开源项目 编辑:程序博客网 时间:2024/04/30 03:18
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等外部资源。































0 0