aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/designers/language-custom-functions/language-function-fetch.md
blob: 2277f5056c04ebb065985dc27f0ec98268baf18b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{fetch} {#language.function.fetch}
=======

`{fetch}` is used to retrieve files from the local file system, http, or
ftp and display the contents.

-   If the file name begins with `http://`, the web site page will be
    fetched and displayed.

    > **Note**
    >
    > This will not support http redirects, be sure to include a
    > trailing slash on your web page fetches where necessary.

-   If the file name begins with `ftp://`, the file will be downloaded
    from the ftp server and displayed.

-   For local files, either a full system file path must be given, or a
    path relative to the executed php script.

    > **Note**
    >
    > If security is enabled and you are fetching a file from the local
    > file system, `{fetch}` will only allow files from within the
    > `$secure_dir` path of the securty policy. See the
    > [Security](#advanced.features.security) section for details.

-   If the `assign` attribute is set, the output of the `{fetch}`
    function will be assigned to this template variable instead of being
    output to the template.

   Attribute Name    Type    Required   Default  Description
  ---------------- -------- ---------- --------- ------------------------------------------------------
        file        string     Yes       *n/a*   The file, http or ftp site to fetch
       assign       string      No       *n/a*   The template variable the output will be assigned to


    {* 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}

      

See also [`{capture}`](#language.function.capture),
[`{eval}`](#language.function.eval),
[`{assign}`](#language.function.assign) and [`fetch()`](#api.fetch).