Fetch content from an external URL in themes
How to fetch content from external URLs into Shoporama themes with the fetch_file function in Smarty 2 or Smarty's built-in fetch function in Smarty 4.
In Shoporama themes, you can fetch content from external URLs directly into your templates. This is useful if you want to show 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, you 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 fetch (http/https only) |
| format | No | Set to json to parse the content as an array. Leave it out for plain text |
| assign | No | The variable name the content is assigned to |
Example: Fetch 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: Fetch as plain text
If you leave out 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, you use Smarty's built-in fetch function:
<{fetch file="https://example.com/data.txt" assign="content"}>
<p><{$content}></p>
Tip
Keep in mind that external requests can affect your page's load time. Consider caching the result or using asynchronous calls via JavaScript if the data is not critical for the initial page view.
Need help? Contact us at support@shoporama.dk.
Related articles
Shoporama themes: an overview of all free store themes
A complete overview of all free themes in Shoporama: Delaware, DelawareDK, California, Alaska 2, Washington, Montana, and the classic Smarty 2...
Language support in themes: translate theme texts with t-tags
How to mark texts in your Shoporama theme with t-tags, so they can be edited in the admin and translated into the language of each of the store's...
Customize the content of your automatic emails
How to customize the automatic emails your Shoporama store sends: without code under Design > Emails, with subject lines and texts in the store...