Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
mysql ステートメントから表示されるテキストの量を制限したいと考えています。たとえば、私のデータベースには、コンテンツ フィールドに 1000 語が含まれているページがあり、そのうちの 200 語だけを表示できるようにしたいと考えています。
TWIGを使用してこれを行うにはどうすればよいですか?
乾杯!
「切り捨て」フィルターを探しているようです。
あなたのapp/config/config.yml追加で::
app/config/config.yml
services: twig.extension.text: class: Twig_Extensions_Extension_Text tags: - { name: twig.extension }
次に、テンプレートで次のことができます。
{{ var.foo | truncate(200) }} {{ "Hello good Sir!" | truncate(4) }}