[PHP] Smarty を Composer でインストールする

21世紀の現在は Smarty を Composer でインストールすることができる。

[markdown]

## Installation

`brew install composer` か `curl -sS https://getcomposer.org/installer | php` で `composer` コマンドを利用できるようにしておきます。

“`prettyprinted
% composer –version
Composer version 1.6.5 2018-05-04 11:44:59
“`

composer.json を用意する。

> * [smarty/smarty – Packagist](https://packagist.org/packages/smarty/smarty)

“`json:composer.json
{
“require”: {
“smarty/smarty”: “~3.1”
}
}
“`

インストールする。

“`prettyprinted
% composer install
“`

## Usage

index.php を用意して、

“`php:index.php
display(‘hello.tpl’);
“`

テンプレートを読み込みます。

“`php:/templates/hello.tpl
Hello, World! by Smarty v{$smarty.version}
“`

PHP ビルトインサーバで確認します。

“`prettyprinted
% php -S localhost:8000
“`

ブラウザに下記が表示されました。

“`prettyprinted
Hello, World! by Smarty v3.1.32
“`

先日見た PHP のシステムに Smarty が使われていたのを見て、なつかしく確認してみました。

> * [DriftwoodJP/sandbox-smarty](https://github.com/DriftwoodJP/sandbox-smarty)

## 補遺

> * [Smarty3 マニュアル | Smarty](https://www.smarty.net/docs/ja/)
> * [SmartyをComposerでインストールする – Qiita](https://qiita.com/yando/items/e55c90c86287d4c785d3)

[/markdown]