Get Smarty

Donate

Paypal

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

Advertisement

{fetch}

{fetch} は、ローカルシステムやhttp, ftpからファイルを取得し、 コンテンツを表示します。

  • ファイル名が http:// から始まる場合は、web サイト上のページを取得して表示します。

    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} の例


{* テンプレートにJavaScriptを含めます *}
{fetch file='/export/httpd/www.example.com/docs/navbar.js'}

{* 他のwebサイトからテンプレートに天候のテキストを埋め込みます *}
{fetch file='http://www.myweather.com/68502/'}

{* ftp経由でニュースヘッドラインファイルを取得します *}
{fetch file='ftp://user:password@ftp.example.com/path/to/currentheadlines.txt'}
{* 上と同じですが、変数を使用します *}
{fetch file="ftp://`$user`:`$password`@`$server`/`$path`"}

{* 取得したコンテンツをテンプレート変数に割り当てます *}
{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.

Advertisement

Sponsors [info]

Sponsors