Get Smarty

Donate

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Shop for 2018 World Cup Football Boots Online sale at guthjcc.com

Browse best 2018 world cup soccer cleats and shoes from SoccerAzteca.com

Advertisement

{fetch}

{fetch}用于获取文件内容、HTTP或者FTP内容,以便输出。

  • 如果提供的文件名是以http://开头,那么网站的内容将被获取并显示。

    Note

    该函数不支持直接的HTTP访问,请确认网页的地址是以斜杠结尾。

  • 如果文件名是以ftp://开头,那么文件会被从FTP中下载并显示。

  • 本地文件而言,可以使用绝对路径的文件,或者相对于当前执行的PHP脚本的路径文件均可。

    Note

    如果开启了安全机制,那么从本地获取文件内容,{fetch}函数仅能读取在 $secure_dir安全目录下的文件。 参见安全机制

  • 如果你提供了assign 属性, {fetch}函数的输出将不会显示,而是赋值给模板变量。

参数名称 类型 必选参数 默认值 说明
file string Yes n/a 获取的文件名、HTTP或者FTP网址
assign string No n/a 用于赋值的变量名

Example 8.5. {fetch} 例子


{* include some javascript in your template *}
{fetch file='/export/httpd/www.example.com/docs/navbar.js'}

{* embed some weather text in your template from another web site *}
{fetch file='http://www.myweather.com/68502/'}

{* fetch a news headline file via ftp *}
{fetch file='ftp://user:password@ftp.example.com/path/to/currentheadlines.txt'}
{* as above but with variables *}
{fetch file="ftp://`$user`:`$password`@`$server`/`$path`"}

{* assign the fetched contents to a template variable *}
{fetch file='http://www.myweather.com/68502/' assign='weather'}
{if $weather ne ''}
  <div id="weather">{$weather}</div>
{/if}

  

参见 {capture}, {eval}, {assign}fetch().

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 1 plus 4? (Are you human?)

Advertisement