1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

僕なりの Twig 備忘録

Last updated at Posted at 2024-06-16

改行と空白を制御したい

課題

改行と空白を-を使って制御したい

不要な改行、不要な空白を削除したい

解決

{%%}のときは左側の-は左側のタグと、右側の-は右側のタグもしくは文字列との改行と空白を制御する。

基本は、タグの後や文字列の前で改行しない状態でのマークアップが最善の形であることを前提と考えていれば問題ない。

詳細

<div>
	{%- if 'yes' == 'yes' -%}
		あああ
	{%- endif -%}
</div>
{# <div>あああ</div> #}

{% set hoge = 'あああ' %}
<div>
{{- hoge -}}
</div>
{# <div>あああ</div> #}
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?