{fetch}

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

参数名称 类型 必选参数 默认值 说明
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().