<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[smarty相加]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 26 Aug 2008 11:40:51 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	参考：http://www.touchboy.cn/html/2006/09/%E5%B7%A7%E7%94%A8math%E5%87%BD%E6%95%B0%E5%9C%A8smarty%E6%A8%A1%E6%9D%BF%E4%B8%AD%E7%BB%99%E5%8F%98%E9%87%8F%E5%8A%A8%E6%80%81%E8%B5%8B%E5%80%BC.html<br/><textarea name="code" class="html" rows="15" cols="100">
&#123;math equation=x x=0 assign=i&#125;
&#123;foreach from=$results item=newsID&#125;
&#123;math equation=$i+1 assign=i&#125;
&#123;if $i%2 == 0&#125;bgcolor=#7B7B7B&#123;else&#125;bgcolor=#B7B7B7&#123;/if&#125;
&lt;/foreach&gt;

&#123;assign&nbsp;&nbsp; var=&quot;nums&quot;&nbsp;&nbsp; value=&quot;1&quot;&#125;&nbsp;&nbsp;&#123;assign&nbsp;&nbsp; var=&quot;nums&quot;&nbsp;&nbsp; value=&quot;1&quot;&#125;
&#123;math equation=&quot;x + y&quot; x=$nums y=8&#125;
</textarea><br/>今天无意中发现了Math函数,感觉很好用,稍加修改就可以达到上述效果: <br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;&lt;!--&#123;math equation=x x=0 assign=i&#125;--&gt; 
&lt;!--&#123;section name=smartyVar loop=10 &#125;--&gt; 
&lt;!--&#123;math equation=$i+1 assign=i&#125;--&gt; 
&lt;br /&gt; 
&lt;!--&#123;$i&#125;--&gt; 
&lt;br /&gt; 
&lt;!--&#123;/section&#125;--&gt; 
</textarea><br/><br/>输出效果:<br/><br/>&lt;br /&gt; <br/>1 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>2 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>3 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>4 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>5 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>6 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>7 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>8 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>9 <br/>&lt;br /&gt; <br/><br/>&lt;br /&gt; <br/>10 <br/>&lt;br /&gt; <br/><br/>如果$i的初始值不是0,例如1,”math equation=x x=1 assign=i”还可以写成”math equation=1 assign=i”,省略其中的x变量.是0时不可以省,否则会出现警告信息Warning: Smarty error: math: missing equation parameter <br/>虽然在模板中再为变量赋值不是一个好主意,但真的需要时可以按上面的方法试一下:)<br/><br/><br/>&nbsp;&nbsp;&#123;$equation&#125;<br/><br/>今天需要用到在smarty模版中将两个变量加起来，根据经验试了好几次，但是都失败了。<br/>googel了一下原来在smarty中将两个变量相加是有专门的函数和结构的，与博友们共享一下：）<br/><br/>&#123;* $height=4, $width=5 *&#125; <br/>&#123;math equation=&quot;x + y&quot; x=$height y=$width&#125; <br/>OUTPUT: <br/>9 <br/><br/><br/>&#123;* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *&#125; <br/>&#123;math equation=&quot;height * width / division&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height=$row_height <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width=$row_width <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;division=#col_div#&#125; <br/>OUTPUT: <br/>100 <br/><br/><br/>&#123;* you can use parenthesis *&#125; <br/>&#123;math equation=&quot;(( x + y ) / z )&quot; x=2 y=10 z=2&#125; <br/>OUTPUT: <br/>6 <br/><br/><br/>&#123;* you can supply a format parameter in sprintf format *&#125; <br/>&#123;math equation=&quot;x + y&quot; x=4.4444 y=5.0000 format=&quot;%.2f&quot;&#125; <br/>OUTPUT: <br/>9.44 
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] smarty相加]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>