Fetch content from external URL in themes
Guide to fetching content from external URLs in Shoporama themes with the Smarty fetch feature.
In Shoporama themes, you can fetch content from external URLs directly into your templates. This is useful if, for example, you want to display data from an external API, load a JSON feed, or include content from another server.

Note
The ` fetch_file ` function is available in Smarty 2 themes. In Smarty 4, use Smarty’s built-in `fetch` function instead.
Syntax and Parameters
The ` fetch_file ` function takes three parameters:
| Parameter | Required | Description |
|---|---|---|
| url | Yes | The URL to be retrieved (http/https only) |
| format | No | Set to " json " to parse as an array. Omit for plain text |
| assign | No | Variable name to which the content is assigned |
Example: Retrieve JSON data
Here, we fetch a JSON file and use the data in the template:
<{fetch_file url="https://example.com/data.json" format="json" assign="data"}>
If the JSON file contains:
{
"name": "Billy Bob",
"email": "billy@example.com"
}
You can now use the data like this:
<p>Name: <{$data.name}></p>
<p>Email: <{$data.email}></p>
Example: Retrieve as plain text
If you omit the format parameter, the content is returned as plain text:
<{fetch_file url="https://example.com/snippet.html" assign="snippet"}>
<div><{$snippet}></div>
Smarty 4: Use `fetch` instead
In Smarty 4 themes, use Smarty’s built-in ` fetch` function:
<{fetch file="https://example.com/data.txt" assign="content"}>
<p><{$content}></p>
Tip
Please note that external calls can affect your page’s load time. Consider caching the result or using asynchronous calls via JavaScript if the data isn’t critical to the initial page view.
Need help? Contact us at support@shoporama.dk.
Related articles
What themes are there on Shoporama?
Complete overview of all free themes on Shoporama: Delaware, DelawareDK, California, Alaska 2, Washington, Montana, and the classic Smarty 2 themes...
Language support in themes
Guide to using the translation feature in Shoporama themes with Smarty t-tags and language files.
Change the content of your emails
Guide to customize the content of the automatic emails your Shoporama webshop sends, either via admin or theme templates.