mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-01 04:41:37 +01:00
119 lines
3.1 KiB
XML
119 lines
3.1 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.modifier.truncate">
|
|
<title>truncate</title>
|
|
<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 the text to append if truncation occurs.</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 (false), or at the exact character (true).</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<para>
|
|
This truncates a variable to a character length, 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, truncate 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>
|
|
<example>
|
|
<title>truncate</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$smarty = new Smarty;
|
|
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
|
$smarty->display('index.tpl');
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
where index.tpl is:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{$articleTitle}
|
|
{$articleTitle|truncate}
|
|
{$articleTitle|truncate:30}
|
|
{$articleTitle|truncate:30:""}
|
|
{$articleTitle|truncate:30:"---"}
|
|
{$articleTitle|truncate:30:"":true}
|
|
{$articleTitle|truncate:30:"...":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...
|
|
]]>
|
|
</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
|
|
--> |