跳至内容

缩进

这缩进每一行字符串,默认是 4。您可以将字符的数量作为可选参数指定给缩进。您可以将要用于缩进的字符作为第二个可选参数指定。例如:使用 "\t" 进行制表符缩进。

基本用法

{$myVar|indent:4}

参数

参数位置 类型 是否必须 默认值 说明
1 整型 4 这决定了要缩进多少个字符。
2 字符串 (一个空格) 用于缩进的字符。

示例

<?php

$smarty->assign('articleTitle',
                'NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.'
                );

模板所在位置

{$articleTitle}

{$articleTitle|indent}

{$articleTitle|indent:10}

{$articleTitle|indent:1:"\t"}

将输出

NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.

    NJ judge to rule on nude beach.
    Sun or rain expected today, dark tonight.
    Statistics show that teen pregnancy drops off significantly after 25.

          NJ judge to rule on nude beach.
          Sun or rain expected today, dark tonight.
          Statistics show that teen pregnancy drops off significantly after 25.

        NJ judge to rule on nude beach.
        Sun or rain expected today, dark tonight.
        Statistics show that teen pregnancy drops off significantly after 25.

另请参阅 stripwordwrapspacify