Files
smarty/docs/en/designers/language-modifiers/language-modifier-truncate.xml
2006-09-26 19:28:45 +00:00

131 lines
3.6 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="language.modifier.truncate">
<title>truncate</title>
<para>
This truncates a variable to a character length, the default is 80.
As an optional second parameter, you can specify a string of text
to display at the end if the variable was truncated. The
characters in the string are included with the original truncation length.
By default, <varname>truncate</varname> will attempt to cut off at a
word boundary. If you want to cut off at the exact character length,
pass the optional third parameter of &true;.
</para>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc"/>
<thead>
<row>
<entry>Parameter Position</entry>
<entry>Type</entry>
<entry>Required</entry>
<entry>Default</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>integer</entry>
<entry>No</entry>
<entry>80</entry>
<entry>This determines how many characters to truncate
to.</entry>
</row>
<row>
<entry>2</entry>
<entry>string</entry>
<entry>No</entry>
<entry>...</entry>
<entry>This is a text string that replaces the truncated text. Its length
is NOT included in the truncation length setting.</entry>
</row>
<row>
<entry>3</entry>
<entry>boolean</entry>
<entry>No</entry>
<entry>&false;</entry>
<entry>This determines whether or not to truncate at a
word boundary with &false;, or at the exact character with &true;.</entry>
</row>
<row>
<entry>4</entry>
<entry>boolean</entry>
<entry>No</entry>
<entry>&false;</entry>
<entry>This determines whether the truncation happens at the end of the
string with &false;, or in the middle of the string with &true;.
Note that if this setting is &true;, then word boundaries are ignored.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<example>
<title>truncate</title>
<programlisting role="php">
<![CDATA[
<?php
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
?>
]]>
</programlisting>
<para>
where template is:
</para>
<programlisting>
<![CDATA[
{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
{$articleTitle|truncate:30:'..':true:true}
]]>
</programlisting>
<para>
This will output:
</para>
<screen>
<![CDATA[
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
Two Sisters Re..ckout Counter.
]]>
</screen>
</example>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->