It's possible it's the various search terms I'm using but I can't seem to find anything close to what I'm looking for.

I am trying to call an external API URL, with keywords from a field, but while I can 'form' the URL outside of the code, inside it breaks.

This is the idea of what I'm trying, based on the plugin's example code...

 {# Get a random Fact form chucknorris.io #}
    {% set jsonData = fetchJson({
      'url': 'https://api.chucknorris.io/jokes&keyword={{ field.name }}&apikey=12345'
    }) %}

    {% if (jsonData) %}
      <h1>Fact of the day</h1>
      {{ jsonData.value }}
    {% endif %}
I don't find a lot of code particularly friendly, so the idea of having a plugin that 'intepreted' it was super exciting - just while it'll pull the URL fine if I type a term in, obviously the brackets are breaking it! 

1 Answer 1


As you found, you're not allowed to nest Twig delimiters. But you don't need to - once inside a Twig statement/block/variable/object/whatever, you can use any Twig variables without delimiters like this using the concatenation operator ~:

{% set jsonData = fetchJson({
      'url': 'https://api.chucknorris.io/jokes&keyword=' ~ field.name ~ '&apikey=12345'
}) %}

Or if you prefer you can use string interpolation (note this requires double quote marks):

{% set jsonData = fetchJson({
      'url': "https://api.chucknorris.io/jokes&keyword=#{field.name}&apikey=12345"
}) %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.