consume

Description

Read an external datasource (either JSON or XML), cache the content and allow you to iterate over the objects.

Syntax

{% consume <variable_name> from <url>(, <options>) %}
...
{% endconsume %}

Example

<p>
  {% consume api from "http://ip.jsontest.com/" %}
  My ip address is: {{ api.ip }}
  {% endconsume %}
</p>

{% consume blog from 'http://blog.locomotivecms.com/api/read/json?num=3&amp;type=text', expires_in: 3000 %}
{% if blog == null %}
  the Tumblr API seems to be broken now.
  {% else %}
    {% for article in blog.posts %}
      {{ article.title }}
    {% endfor %}
  {% endif %}
{% endconsume %}

Caching

For the caching, the LocomotiveCMS engine uses the default Rails caching.

If you want to use the Redis cache store, please read this blog article.

Options

Name Type Description
expires_in Integer Delay in seconds during the content will be cached. 0 means no cache.
username String username if the external API requires an HTTP authentication.
password String password if the external API requires an HTTP authentication.
© 2024 LocomotiveCMS Terms of use Privacy Policy
Back to top