<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="language.syntax.comments.html" accesskey="P">Prev</a></td> <td width="50%" align="center" valign="bottom">Chapter 3. Basic Syntax[第3章.基本語法]</td> <td width="25%" align="right" valign="bottom"><a href="language.syntax.functions.html" accesskey="N">Next</a></td></tr></table> # Variables[變量] Template variables start with the $dollar sign. They can contain numbers, letters and underscores, much like a PHP variable [http://php.net/language.variables]. You can reference arrays by index numerically or non-numerically. Also reference object properties and methods. Config file variables are an exception to the $dollar syntax and are instead referenced with surrounding #hashmarks#, or via the $smarty.config variable. 模板變量用美元符號$開始,可以包含數字、字母和下劃線,這與[php變量](http://php.net/language.variables)很像。你可以引用數組的數字或非數字索引,當然也可以引用對象屬性和方法。 譯注 | 譯注:按照說明像$abc、$abc123、$abc_123、$abc[1]、$abc['a']、$abc->a、$abc->a()這些模板變量都是有效的。 | |-----| 配置文件變量是一個不用美元符號$,而是用#號包圍著變量(#hashmarks#),或者是一個$smarty.config形式的變量。 **Example 3-2. 變量** | ~~~ {* 演示server變量"SERVER_NAME"($_SERVER['SERVER_NAME']) *}{$smarty.server.SERVER_NAME}數學和嵌入標簽:{$x+$y} // 輸出x+y的和.{assign var=foo value=$x+$y} // 屬性中的變量 {$foo[$x+3]} // 變量作為數組索引{$foo={counter}+3} // 標簽里面嵌套標簽{$foo="this is message {counter}"} // 引號里面使用標簽定義數組:{assign var=foo value=[1,2,3]}{assign var=foo value=['y'=>'yellow','b'=>'blue']}{assign var=foo value=[1,[9,8],3]} // 可以嵌套短變量分配:{$foo=$bar+2}{$foo = strlen($bar)} // function in assignment{$foo = myfunct( ($x+$y)*3 )} // 作為函數參數 {$foo.bar=1} // 賦值給指定的數組索引{$foo.bar.baz=1} {$foo[]=1} // appending to an arraySmarty "dot" 語法 (注意: 嵌入的{}用來解決指代不明的情況):{$foo.a.b.c} => $foo['a']['b']['c'] {$foo.a.$b.c} => $foo['a'][$b]['c'] // with variable index{$foo.a.{$b+4}.c} => $foo['a'][$b+4]['c'] // 表達式作為索引{$foo.a.{$b.c}} => $foo['a'][$b['c']] // 嵌套索引PHP式語法, "dot"語法外的另一種選擇:{$foo[1]} // normal access{$foo['bar']}{$foo['bar'][1]}{$foo[$x+$x]} // index may contain any expression{$foo[$bar[1]]} // nested index{$foo[section_name]} // smarty {section} access, not array access! 訪問Smarty節塊變量,而非訪問數組可變變量:$foo // normal variable$foo_{$bar} // variable name containing other variable $foo_{$x+$y} // variable name containing expressions $foo_{$bar}_buh_{$blar} // variable name with multiple segments 用在多段變量名中{$foo_{$x}} // will output the variable $foo_1 if $x has a value of 1 注意是輸出變量,而非值對象鏈:{$object->method1($x)->method2($y)}直接使用php函數:{time()} //譯注:如果直接使用模版變量符號引用php函數,該函數應有返回值。 ~~~ | |-----| <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td><p>Note<br/> Although Smarty can handle some very complex expressions and syntax, it is a good rule of thumb to keep the template syntax minimal and focused on presentation. If you find your template syntax getting too complex, it may be a good idea to move the bits that do not deal explicitly with presentation to PHP by way of plugins or modifiers.</p> <p>雖然Smarty能處理一些復雜的表達式和語法,但從經驗上來說的,一個好的做法是最低限度使用模版語法,將其專注于表現外在內容。如果發現你的模版語法太復雜,最好將與外在表現無關的后臺處理通過插件或調節器交給php處理。</p></td> </tr></table> Request variables such as $_GET, $_SESSION, etc are available via the reserved $smarty variable. See also $smarty, config variables {assign} and assign(). 確定可以經由$smarty保留變量使用$_GET、$_SESSION等php全局超級變量。 更多參考[$smarty](#)、賦值變量[{assign}](#)和[assign()](#)。 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="language.syntax.comments.html" accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="language.syntax.functions.html" accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Comments<br/> 注釋</td><td width="34%" align="center" valign="top"><a href="language.basic.syntax.html" accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Functions<br/> 函數</td></tr></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看