4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FuelPHP & Twig で truncateフィルタを使う方法

Last updated at Posted at 2014-09-15

概要

FuelPHPでテンプレートエンジンにTwigを使用していてtruncateフィルタを使いたくなったんだけどFuelPHPデフォルトでは使えず。ググってもこれといった資料が見つからず試行錯誤してなんとか使えるに至ったのでメモ。

やりたいこと

truncateはこちら
こんな感じに長い文字列をview内で切り詰めたい

<span>{{ long_description|truncate(30) }}</span>

方法

1. twig/extensions をインストールする

$ php composer.phar require twig/extensions "~1.0"

2. config/parser.php を編集する

fuel/app/config/parser.php
	'View_Twig' => array(

		....

		'extensions' => array(
			'Twig_Fuel_Extension',
			'Twig_Extensions_Extension_Text',  //追加!
		),
	),
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?