Emergency

In urgent situations or outages, you can send a text message to our emergency line

Emergency line (text message only)

+45 29 70 15 95

Send a text message with the following information:

  • Your name and webshop
  • A description of the problem

Note: This service is only for critical situations where your webshop is down or has serious problems. For regular support, please use our normal support channels.

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.

Reading time: about 4 minutes
Developer

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.

The code editor in the Shoporama admin with the file list for the MBN-Delaware theme and the Smarty code from the after_purchase.html email template open for editing.
You find the code editor under Design → Code editor. The theme's file list is on the left, and you edit the Smarty code itself on the right.

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
urlYesThe URL to fetch (http/https only)
formatNoSet to json to parse the content as an array. Leave it out for plain text
assignNoThe 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.