mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
fixing some more examples
This commit is contained in:
@@ -58,26 +58,26 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
</sect1>
|
||||
</chapter>
|
||||
<chapter id="tips">
|
||||
<title>Tips & Tricks</title>
|
||||
<title>Tips & Tricks</title>
|
||||
<para>
|
||||
</para>
|
||||
<sect1 id="tips.blank.var.handling">
|
||||
<title>Blank Variable Handling</title>
|
||||
<para>
|
||||
There may be times when you want to print a default value for an empty
|
||||
variable instead of printing nothing, such as printing "&nbsp;" so that
|
||||
variable instead of printing nothing, such as printing " " so that
|
||||
table backgrounds work properly. Many would use an {if} statement to
|
||||
handle this, but there is a shorthand way with Smarty, using the
|
||||
<emphasis>default</emphasis> variable modifier.
|
||||
</para>
|
||||
<example>
|
||||
<title>Printing &nbsp; when a variable is empty</title>
|
||||
<title>Printing when a variable is empty</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* the long way *}
|
||||
|
||||
{if $title eq ""}
|
||||
&nbsp;
|
||||
|
||||
{else}
|
||||
{$title}
|
||||
{/if}
|
||||
@@ -85,7 +85,7 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
|
||||
{* the short way *}
|
||||
|
||||
{$title|default:"&nbsp;"}
|
||||
{$title|default:" "}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
@@ -144,17 +144,17 @@ archives.tpl
|
||||
|
||||
header.tpl
|
||||
----------
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>{$title|default:"BC News"}</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>{$title|default:"BC News"}</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
|
||||
footer.tpl
|
||||
----------
|
||||
</BODY>
|
||||
</HTML>
|
||||
</BODY>
|
||||
</HTML>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
@@ -199,7 +199,7 @@ OUTPUT:
|
||||
2001/01/04
|
||||
|
||||
|
||||
{if $date1 < $date2}
|
||||
{if $date1 < $date2}
|
||||
...
|
||||
{/if}
|
||||
]]>
|
||||
@@ -270,28 +270,28 @@ function insert_header($params) {
|
||||
<![CDATA[
|
||||
{insert name=header content="Content-Type: text/vnd.wap.wml"}
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
|
||||
|
||||
<!-- begin new wml deck -->
|
||||
<wml>
|
||||
<!-- begin first card -->
|
||||
<card>
|
||||
<do type="accept">
|
||||
<go href="#two"/>
|
||||
</do>
|
||||
<p>
|
||||
<!-- begin new wml deck -->
|
||||
<wml>
|
||||
<!-- begin first card -->
|
||||
<card>
|
||||
<do type="accept">
|
||||
<go href="#two"/>
|
||||
</do>
|
||||
<p>
|
||||
Welcome to WAP with Smarty!
|
||||
Press OK to continue...
|
||||
</p>
|
||||
</card>
|
||||
<!-- begin second card -->
|
||||
<card id="two">
|
||||
<p>
|
||||
</p>
|
||||
</card>
|
||||
<!-- begin second card -->
|
||||
<card id="two">
|
||||
<p>
|
||||
Pretty easy isn't it?
|
||||
</p>
|
||||
</card>
|
||||
</wml>
|
||||
</p>
|
||||
</card>
|
||||
</wml>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
@@ -328,7 +328,7 @@ function fetch_ticker($symbol) {
|
||||
return $ticker_info;
|
||||
}
|
||||
|
||||
function smarty_function_load_ticker($params, &$smarty) {
|
||||
function smarty_function_load_ticker($params, &$smarty) {
|
||||
// call the function
|
||||
$ticker_info = fetch_ticker($params['symbol']);
|
||||
|
||||
|
@@ -1069,7 +1069,7 @@ index.tpl:
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|escape}
|
||||
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
|
||||
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
|
||||
{$articleTitle|escape:"htmlall"} {* escapes ALL html entities *}
|
||||
{$articleTitle|escape:"url"}
|
||||
{$articleTitle|escape:"quotes"}
|
||||
@@ -1078,12 +1078,12 @@ index.tpl:
|
||||
OUTPUT:
|
||||
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
|
||||
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
|
||||
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
'Stiff Opposition Expected to Casketless Funeral Plan'
|
||||
%27Stiff+Opposition+Expected+to+Casketless+Funeral+Plan%27
|
||||
\'Stiff Opposition Expected to Casketless Funeral Plan\'
|
||||
<a href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">&#x62;&#x6f;&#x62;&#x40;&#x6d;&#x65;&#x2e;&#x6e;&#x65;&#x74;</a></programlisting>
|
||||
<a href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">bob@me.net</a></programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.modifier.indent">
|
||||
@@ -1267,7 +1267,7 @@ $smarty->display('index.tpl');
|
||||
|
||||
index.tpl:
|
||||
|
||||
{* replace each carriage return, tab & new line with a space *}
|
||||
{* replace each carriage return, tab & new line with a space *}
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
|
||||
@@ -1477,14 +1477,14 @@ index.tpl:
|
||||
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip}
|
||||
{$articleTitle|strip:"&nbsp;"}
|
||||
{$articleTitle|strip:" "}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
Grandmother of
|
||||
eight makes hole in one.
|
||||
Grandmother of eight makes hole in one.
|
||||
Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&nbsp;one.</programlisting>
|
||||
Grandmother of eight makes hole in one.</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.modifier.strip.tags">
|
||||
@@ -2480,7 +2480,7 @@ index.tpl
|
||||
<emphasis>{/if}</emphasis>. <emphasis>{else}</emphasis> and
|
||||
<emphasis>{elseif}</emphasis> are also permitted. All PHP conditionals
|
||||
are recognized, such as <emphasis>||</emphasis>, <emphasis>or</emphasis>,
|
||||
<emphasis>&&</emphasis>, <emphasis>and</emphasis>, etc.
|
||||
<emphasis>&&</emphasis>, <emphasis>and</emphasis>, etc.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -3731,7 +3731,7 @@ index.tpl
|
||||
OUTPUT:
|
||||
|
||||
This is the contents of foo.
|
||||
Welcome to Foobar Pub & Grill's home page!
|
||||
Welcome to Foobar Pub & Grill's home page!
|
||||
You must supply a <b>city</b>.
|
||||
You must supply a <b>state</b>.
|
||||
|
||||
@@ -5007,7 +5007,7 @@ OUTPUT:
|
||||
<entry>trailpad</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>&nbsp;</emphasis></entry>
|
||||
<entry><emphasis> </emphasis></entry>
|
||||
<entry>value to pad the trailing cells on last row with
|
||||
(if any)</entry>
|
||||
</row>
|
||||
@@ -5067,12 +5067,12 @@ OUTPUT:
|
||||
<table border="0">
|
||||
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
|
||||
<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr>
|
||||
<tr><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
|
||||
<tr><td>9</td><td> </td><td> </td><td> </td></tr>
|
||||
</table>
|
||||
<table border="1">
|
||||
<tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr>
|
||||
<tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr>
|
||||
<tr bgcolor="#eeeeee"><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
|
||||
<tr bgcolor="#eeeeee"><td>9</td><td> </td><td> </td><td> </td></tr>
|
||||
</table></programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
@@ -5325,8 +5325,8 @@ OUTPUT:
|
||||
9%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%
|
||||
61%69%6e%2e%63%6f%6d%22%20%3e%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e
|
||||
%27%29%3b'))</script>
|
||||
<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" >&#x6d;&#x65;&#x40;&#x64;&
|
||||
#x6f;&#x6d;&#x61;&#x69;&#x6e;&#x2e;&#x63;&#x6f;&#x6d;</a>
|
||||
<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" >me@d&
|
||||
#x6f;main.com</a>
|
||||
<a href="mailto:me@domain.com?subject=Hello%20to%20you%21" >me@domain.com</a>
|
||||
<a href="mailto:me@domain.com?cc=you@domain.com%2Cthey@domain.com" >me@domain.com</a>
|
||||
<a href="mailto:me@domain.com" class="email">me@domain.com</a></programlisting>
|
||||
|
Reference in New Issue
Block a user