# 安裝
其實,安裝Twig有多種方法。
### 安裝Twig PHP package
通過Composer安裝(推薦)
安裝 [Composer](https://getcomposer.org/download/),然后運行以下命令獲取最新版Twig:
~~~
composer require twig/twig:~1.0
~~~
### 安裝壓縮包版
1. 從[下載頁面](https://github.com/twigphp/Twig/tags)下載最新的壓縮包。
1. 驗證壓縮包的完整性 [http://fabien.potencier.org/article/73/signing-project-releases](http://fabien.potencier.org/article/73/signing-project-releases)
1. 解壓壓縮包
1. 將文件移入你的項目內容合適的目錄中。
### 安裝開發版
~~~
git clone git://github.com/twigphp/Twig.git
~~~
### 安裝 PEAR 包
注意:
> 通過 PEAR 安裝Twig已被棄用,Twig 1.15.1是發布在 PEAR頻道的最新版;使用Composer替代它吧。
~~~
pear channel-discover pear.twig-project.org
pear install twig/Twig
~~~
### 安裝C擴展
> Twig 1.4版本加入的新東西。
注意:
> C擴展是**可選的**,它帶來了一些很不錯的性能提升。記住,擴展程序不是PHP代碼的替代品。它只是實現了部分PHP代碼,使其在運行時刻(runtime)提升性能。你仍然必須安裝原生PHP代碼。
Twig的C擴展增強了Twig運行引擎的性能。像安裝其他PHP擴展那樣安裝它:
~~~
cd ext/twig
phpize
./configure
make
make install
~~~
Windows 平臺:
1. 參照[PHP文檔](https://wiki.php.net/internals/windows/stepbystepbuild)設置構建環境。
1. 將Twig的C擴展源代碼放入`C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig`
1. 使用`configure --disable-all --enable-cli --enable-twig=shared` 命令,替代第十四步。
1. `nmake`
1. 復制`C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll`文件到PHP設置中。
最后,在`php.ini`配置文件中啟用擴展。
~~~
extension=twig.so #For Unix systems
extension=php_twig.dll #For Windows systems
~~~
從現在起,Twig將利用C擴展自動編譯你的模板。記住,該擴展并不替代PHP代碼,但提供了`Twig_Template::getAttribute()`方法的優化版。
- 首頁
- 目錄
- 介紹
- 安裝
- 面向模板設計師
- 面向開發者
- 擴展 Twig
- Twig的內部構建
- 棄用的特性
- 使用技巧
- 代碼規范
- 標簽 tags
- autoescape
- block
- do
- embed
- extends
- filter
- flush
- for
- from
- if
- import
- include
- macro
- sandbox
- set
- spaceless
- use
- verbatim
- 過濾器
- abs
- batch
- capitalize
- convert_encoding
- date
- date_modify
- default
- escape
- first
- format
- join
- json_encode
- keys
- last
- length
- lower
- merge
- nl2br
- number_format
- raw
- replace
- reverse
- round
- slice
- sort
- split
- striptags
- title
- trim
- upper
- url_encode
- 函數
- attribute
- block
- constant
- cycle
- date
- dump
- include
- max
- min
- parent
- random
- range
- source
- template_from_string
- 測試
- constant
- defined
- divisibleby
- empty
- even
- iterable
- null
- odd
- sameas