4
4

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.

phpとSmartyの環境でモバイルサイトから余計な余白/インデントを自動的に削除

Posted at

モバイルサイトで容量の制限や表示への影響を考慮してインデントしない方が無難です。

しかし、インデントのないソースコードは見る気さえなくなってしまいますよね。

Smartyを使っているのなら、この問題を簡単に解決できる!

ソースコード全体を strip タグで囲めばコンパイル時に自動的に余計な余白とインデントが削除されます。

この醜いソースコードが

<div>{% if $type == 'show' %}公開中{% else %}<a href='./visibility/show'>公開中</a>{% /if %}/{% if $type == 'hide' %}非公開中{% else %}<a href='./visibility/hide'>非公開中</a>{% /if %}</div>
<div style="text-align:center">
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
xxxxxxxxxxxxxx
</td>
</tr>
</table>
</div>

美しいソースコードに変身します

{% strip %}
<div>
    {% if $type == 'show' %}
        公開中
    {% else %}
        <a href='./visibility/show'>公開中</a>
    {% /if %}
    /
    {% if $type == 'hide' %}
        非公開中
    {% else %}
        <a href='./visibility/hide'>非公開中</a>
    {% /if %}
</div>
<div style="text-align:center">
    <table border="0" cellpadding="4" cellspacing="0">
        <tr>
            <td>
                xxxxxxxxxxxxxx
            </td>
        </tr>
    </table>
</div>
{% /strip %}
4
4
4

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
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?