Files
smarty/docs/en/designers/language-custom-functions/language-function-fetch.xml

138 lines
3.9 KiB
XML
Raw Normal View History

2004-04-13 08:46:28 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2004-05-29 21:56:21 +00:00
<sect1 id="language.function.fetch">
<title>{fetch}</title>
2005-09-13 19:03:11 +00:00
<para>
<varname>{fetch}</varname> is used to retrieve files from the
local file system, http, or ftp and display the contents.
</para>
<itemizedlist>
<listitem><para>
If the file name begins with
<parameter>http://</parameter>, the web site page will be fetched and displayed.
<note>
<para>
This will not support http redirects, be sure to
include a trailing slash on your web page fetches where necessary.
</para>
</note>
</para></listitem>
<listitem><para>
If the file name begins with <parameter>ftp://</parameter>, the file will
be downloaded from the ftp server and displayed.
</para></listitem>
<listitem><para>
For local files, either a full system file path
must be given, or a path relative to the executed php script.
<note>
<para>
If template <link linkend="variable.security">
<parameter>$security</parameter></link>
is enabled and you are
fetching a file from the local file system, <varname>{fetch}</varname>
will only allow files from within one of the defined
<link linkend="variable.secure.dir">secure directories</link>.
</para>
</note>
</para></listitem>
<listitem><para>
If the <parameter>assign</parameter> attribute is set, the output of the
<varname>{fetch}</varname> function will be assigned to this template
variable instead of being output to the template.
</para></listitem>
</itemizedlist>
2004-05-29 21:56:21 +00:00
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>Attribute Name</entry>
<entry>Type</entry>
<entry>Required</entry>
<entry>Default</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>file</entry>
<entry>string</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>The file, http or ftp site to fetch</entry>
2004-05-29 21:56:21 +00:00
</row>
<row>
<entry>assign</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>The template variable the output will be assigned
2004-05-29 21:56:21 +00:00
to</entry>
</row>
</tbody>
</tgroup>
</informaltable>
2005-09-13 19:03:11 +00:00
2004-05-29 21:56:21 +00:00
<example>
2006-03-13 22:48:14 +00:00
<title>{fetch} examples</title>
2004-05-29 21:56:21 +00:00
<programlisting>
<![CDATA[
2004-04-13 08:46:28 +00:00
{* include some javascript in your template *}
2006-03-13 22:48:14 +00:00
{fetch file='/export/httpd/www.example.com/docs/navbar.js'}
2004-04-13 08:46:28 +00:00
{* embed some weather text in your template from another web site *}
2006-03-13 22:48:14 +00:00
{fetch file='http://www.myweather.com/68502/'}
2004-04-13 08:46:28 +00:00
{* fetch a news headline file via ftp *}
2006-03-13 22:48:14 +00:00
{fetch file='ftp://user:password@ftp.example.com/path/to/currentheadlines.txt'}
{* as above but with variables *}
{fetch file="ftp://`$user`:`$password`@`$server`/`$path`"}
2004-04-13 08:46:28 +00:00
{* assign the fetched contents to a template variable *}
2006-03-13 22:48:14 +00:00
{fetch file='http://www.myweather.com/68502/' assign='weather'}
{if $weather ne ''}
<div id="weather">{$weather}</div>
2004-05-29 21:56:21 +00:00
{/if}
2004-05-29 22:01:12 +00:00
]]>
2004-05-29 21:56:21 +00:00
</programlisting>
</example>
<para>
See also
<link linkend="language.function.capture"><varname>{capture}</varname></link>,
<link linkend="language.function.eval"><varname>{eval}</varname></link>,
<link linkend="language.function.assign"><varname>{assign}</varname></link>
and
<link linkend="api.fetch"><varname>fetch()</varname></link>.
</para>
2004-04-13 08:46:28 +00:00
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->