Home > Backend Development > PHP Tutorial > symfony2 twig模板引擎

symfony2 twig模板引擎

WBOY
Release: 2016-07-29 09:02:29
Original
884 people have browsed it

1、基本语法

Says something:{{    }}

Does something:{%  %}

Comment something:{#    #}

{% extends "AppWebBundle::layout.html.twig" %}继承模板

2、核心概念:

用类的继承关系去管理页面之间的关系

如果要访问某个bundle里的资源文件,需要将文件拷贝到/web 目录下,或者linux/mac 软连接映射到/web目录下

windows:  >php app/console assets:install web

linux:  >php app/console assets:install web --symlink --relative

3、js css文件管理

(1)直接使用某个CSS/JS文件:{{asset('xxx.js')}}

(2)注册/定义资源:{% javascripts %} {% stylesheets %}

# 会将‘AppWebBundle/Resources/public/js/’目录下所有的js文件依次输出<br>{% block my_js %<span>}
    {</span>% javascripts '@AppWebBundle/Resources/public/js/*' %<span>}
        </span><script type="text/javascript" src="%7B%7B%20asset_url%20%7D%7D"></script><span>    {</span>% endjavascripts %<span>}
{</span>% endblock %}
Copy after login

并在app/config/config.yml配置:

assetic:<span>    bundles</span>:        [ AppWebBundle ]
Copy after login

(3)页面间共享CSS/JS文件的通用策略

symfony2 twig模板引擎

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template