Gallery: 主题:参考:修改器:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
 
第1行: 第1行:
==Smarty Modifier Basics==
==Smarty修改器基础==
[http://smarty.php.net Smarty] uses modifiers to display text in different ways, for example to display as a string in capital letters, small letters, or title case.  Any variable in a template can have a modifier applied to it by following it with a pipe symbol ('<code>|</code>') and the name of a modifier:
[http://smarty.php.net Smarty]使用修改器来用不同的方式显示文本,比如将一个字串显示为大写字母,小写字母或标题。模板中的任何变量都可以被应用上一个修改器,只要带上一个竖杠标记('<code>|</code>')和某修改器名称即可:


===Using Modifiers===
===使用修改器===
{| style="margin-left:10px; border: lightgray thin dotted;"
{| style="margin-left:10px; border: lightgray thin dotted;"
|-
|-
|width="350px"|<code>{$user.userName}</code> ||Displays the variable <code>$user.userName</code> without any change in formatting
|width="350px"|<code>{$user.userName}</code> ||不改变格式的情况下显示变量<code>$user.userName</code>
|-  
|-  
|<code><nowiki>{$user.userName|upper}</nowiki></code> || Displays the variable <code>$user.userName</code> in upper case letters using the <code>upper</code> modifier
|<code><nowiki>{$user.userName|upper}</nowiki></code> || 使用<code>upper</code>修改器以大写字母显示变量<code>$user.userName</code>
|-
|-
|}
|}


===Chaining Several Modifiers Together===
===将若干个修改器串链在一起===
Several modifiers can be chained together by separating each with a pipe symbol:
使用竖杠就可以将若干个修改器串链在一起了:


{| style="margin-left:10px; border: lightgray thin dotted;"
{| style="margin-left:10px; border: lightgray thin dotted;"
|-
|-
|width="350px"|<code>{$user.userName|upper|strip_tags}</code> ||Displays the variable <code>$user.userName</code> applying the <code>upper</code> modifier first followed by the <code>strip_tags</code> modifier
|width="350px"|<code>{$user.userName|upper|strip_tags}</code> ||先使用<code>upper</code>修改器接着是<code>strip_tags</code>修改器的方式来显示变量<code>$user.userName</code>  
|-
|-
|}
|}


===Using Parameters with Modifiers===
===对修改器使用参量===
Certain modifiers can take parameters to control their behaviour, for example the built-in Smarty modifier <code>truncate</code> which truncates a string to a given length.  The desired length of the string is passed as a parameter to the modifier:
某些修改器可以使用参量来控制它们的行为,比如内置的Smarty修改器 <code>truncate</code>可以截取给定长度的字串。期望的字串长度作为一个参量传输给修改器:


{| style="margin-left:10px; border: lightgray thin dotted;"
{| style="margin-left:10px; border: lightgray thin dotted;"
|-
|-
|width="350px"|<code>{$user.userName|truncate:20}</code> ||Displays the variable <code>$user.userName</code> truncated to 20 characters in length
|width="350px"|<code>{$user.userName|truncate:20}</code> ||以20个字符的长度显示变量<code>$user.userName</code>
|-
|-
|}
|}


If a modifier has several parameters, they must be passed in sequences, separated by colons.  Optional parameters that you do not wish to specify a value for are given by omitting any value after its colon:
如果一个修改器有若干个参量的话,它们就必须按顺序进行传输,以冒号隔开。不愿为其赋值的可选参量的冒号之后的数值将被省略掉:


{| style="margin-left:10px; border: lightgray thin dotted;"
{| style="margin-left:10px; border: lightgray thin dotted;"
|-valign="top"
|-valign="top"
|width="350px"|<code>{$user.userName|truncate:20::true:true}</code> ||Displays the variable <code>$user.userName</code> and passes four parameters to the <code>truncate</code> modifier:
|width="350px"|<code>{$user.userName|truncate:20::true:true}</code> ||显示变量<code>$user.userName</code>并向<code>truncate</code>修改器传输四个参量:


*Parameter 1 = 20 - the length to truncate at
*Parameter 1 = 20 - the length to truncate at
第42行: 第42行:
|}
|}


===Further Information on Modifiers===
===深入了解修改器===
Further information on using modifiers in templates, and the built-in modifiers in Smarty, can be found in the
有关在模板中使用修改器以及Smarty中内置修改器的更详细信息可在
[http://www.smarty.net/manual/en/plugins.modifiers.php Smarty manual].
[http://www.smarty.net/manual/en/plugins.modifiers.php Smarty 手册]中找到。


==Gallery2 Smarty Modifiers==
==Gallery2的Smarty修改器==
Gallery2 adds some extra modifiers to Smarty that help to format text for use in a gallery.  These are:
Gallery2向Smarty添加额外的修改器进行文本格式化以为gallery所用。包括有:


===entitytruncate===
===entitytruncate===
Usage: '''<code>entitytruncate</code>'''''<code>:length:etc:breakWords</code>''
用法: '''<code>entitytruncate</code>'''''<code>:length:etc:breakWords</code>''


The <code>entitytruncate</code> modifier truncates a string, but avoids making the truncation in the middle of an HTML entity or a multibyte character
<code>entitytruncate</code> 修改器截取一个字串,但禁止在HTML实体或multibyte字符的中部的截取


Parameters:
参量:
*''<code>length</code>'' (integer)- maximum length for output string
*''<code>length</code>''(整数)-输出字段的最大长度
*''<code>etc</code>'' (string) - a string to append to the end of a truncated string; the default is three full-stops ('...')
*''<code>etc</code>''(字串)-用于后置到某被截取的字串,默认为3个句号('...'
*''<code>breakWords</code>'' (boolean) - if true, <code>entitytruncate</code> will break a string in the middle of a word.  The default is <code>false</code>
*''<code>breakWords</code>'' (boolean) – 如为true,<code>entitytruncate</code>将在中部截断某字串。默认为<code>false</code>


===ireplace===
===ireplace===
Usage: '''<code>ireplace</code>'''''<code>:search:replace</code>''
用法: '''<code>ireplace</code>'''''<code>:search:replace</code>''


<code>ireplace</code> performs a case insensitive search and replace on the variable it modifies, replacing <code>search</code> with <code>replace</code>
<code>ireplace</code>作为一个大小写敏感的搜索,并替换它所修改的变量,将<code>search</code>替换为<code>replace</code>


Parameters:
参量:
*''<code>search</code>'' (string) - a string to find in the variable
*''<code>search</code>''(字串)-变量中进行查找的字串
*''<code>replace</code>'' (string) - a string to replace <code>search</code> with
*''<code>replace</code>''(字串)-替换<code>search</code>的字串


===markup===
===markup===
Usage: '''<code>markup</code>'''
用法: '''<code>markup</code>'''


The <code>markup</code> modifier formats a variable according to the markup format set in the Site Admin settings (raw HTML, BBCode, or no formatting)
<code>markup</code>修改器根据站点管理设定中设置的标记格式(raw HTML,BBCode或无格式)来格式化某个变量


===print_r===
===print_r===
Usage: '''<code>print_r</code>'''
用法: '''<code>print_r</code>'''


This modifier is used for debugging purposes and prints a variable recursively if it contains subkeys.  More information on the <code>print_r</code> keyword is available in the [http://php.net/print_r PHP Manual]
此修改器用于debug,并且如果某变量含有子键(subkey)的话,就会递归式地将其打印出来。更多有关<code>print_r</code>关键词的信息可在[http://php.net/print_r PHP手册]中找到


===repeat===
===repeat===
Usage: '''<code>repeat</code>'''''<code>:count</code>''
用法: '''<code>repeat</code>'''''<code>:count</code>''


The <code>repeat</code> modifier repeats the variable a given number of times
<code>repeat</code>修改器按指定次数重复某变量


Parameters:
参量:
*''<code>count</code>'' (integer) - the number of times to repeat the variable that this <code>repeat</code> is modifying
*''<code>count</code>''(整数)-<code>repeat</code>所修改的变量重复次数


===split===
===split===
Usage: '''<code>split</code>'''''<code>:separator:regexp</code>''
用法: '''<code>split</code>'''''<code>:separator:regexp</code>''


<code>split</code> splits a variable into an array using the separator given.  Further information on <code>split</code> is available in the [http://php.net/split PHP Manual]  
<code>split</code> 将某变量截断为使用给定分隔符的数组。有关<code>split</code>的更多信息可在[http://php.net/split PHP手册]中查到


Parameters:
参量:
*''<code>separator</code>'' (string) - the string that marks the points where the variable should be split
*''<code>separator</code>''(字串)–此字串标注变量应被截断的位置
*''<code>regexp</code>'' (boolean) - if <code>true</code> then <code>separator</code> is interpreted as a regular expression.  The default is <code>false</code>
*''<code>regexp</code>'' (boolean) - if <code>true</code> then <code>separator</code>解析为一个正则表达式。默认为<code>false</code>


[[Category:Gallery 2:Development]]
[[Category:Gallery 2:Development]]

2008年8月9日 (六) 15:56的最新版本

Smarty修改器基础[编辑 | 编辑源代码]

Smarty使用修改器来用不同的方式显示文本,比如将一个字串显示为大写字母,小写字母或标题。模板中的任何变量都可以被应用上一个修改器,只要带上一个竖杠标记('|')和某修改器名称即可:

使用修改器[编辑 | 编辑源代码]

{$user.userName} 不改变格式的情况下显示变量$user.userName
{$user.userName|upper} 使用upper修改器以大写字母显示变量$user.userName

将若干个修改器串链在一起[编辑 | 编辑源代码]

使用竖杠就可以将若干个修改器串链在一起了:

{$user.userName|upper|strip_tags} 先使用upper修改器接着是strip_tags修改器的方式来显示变量$user.userName

对修改器使用参量[编辑 | 编辑源代码]

某些修改器可以使用参量来控制它们的行为,比如内置的Smarty修改器 truncate可以截取给定长度的字串。期望的字串长度作为一个参量传输给修改器:

{$user.userName|truncate:20} 以20个字符的长度显示变量$user.userName

如果一个修改器有若干个参量的话,它们就必须按顺序进行传输,以冒号隔开。不愿为其赋值的可选参量的冒号之后的数值将被省略掉:

{$user.userName|truncate:20::true:true} 显示变量$user.userName并向truncate修改器传输四个参量:
  • Parameter 1 = 20 - the length to truncate at
  • Parameter 2 = optional and not specified
  • Parameter 3 = true
  • Parameter 4 = true

深入了解修改器[编辑 | 编辑源代码]

有关在模板中使用修改器以及Smarty中内置修改器的更详细信息可在 Smarty 手册中找到。

Gallery2的Smarty修改器[编辑 | 编辑源代码]

Gallery2向Smarty添加额外的修改器进行文本格式化以为gallery所用。包括有:

entitytruncate[编辑 | 编辑源代码]

用法: entitytruncate:length:etc:breakWords

entitytruncate 修改器截取一个字串,但禁止在HTML实体或multibyte字符的中部的截取

参量:

  • length(整数)-输出字段的最大长度
  • etc(字串)-用于后置到某被截取的字串,默认为3个句号('...')
  • breakWords (boolean) – 如为true,entitytruncate将在中部截断某字串。默认为false

ireplace[编辑 | 编辑源代码]

用法: ireplace:search:replace

ireplace作为一个大小写敏感的搜索,并替换它所修改的变量,将search替换为replace

参量:

  • search(字串)-变量中进行查找的字串
  • replace(字串)-替换search的字串

markup[编辑 | 编辑源代码]

用法: markup

markup修改器根据站点管理设定中设置的标记格式(raw HTML,BBCode或无格式)来格式化某个变量

print_r[编辑 | 编辑源代码]

用法: print_r

此修改器用于debug,并且如果某变量含有子键(subkey)的话,就会递归式地将其打印出来。更多有关print_r关键词的信息可在PHP手册中找到

repeat[编辑 | 编辑源代码]

用法: repeat:count

repeat修改器按指定次数重复某变量

参量:

  • count(整数)-此repeat所修改的变量重复次数

split[编辑 | 编辑源代码]

用法: split:separator:regexp

split 将某变量截断为使用给定分隔符的数组。有关split的更多信息可在PHP手册中查到

参量:

  • separator(字串)–此字串标注变量应被截断的位置
  • regexp (boolean) - if true then separator解析为一个正则表达式。默认为false