<p>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 <a href="https://twig.symfony.com/doc/3.x/templates.html#other-operators" rel="nofollow noreferrer">concatenation operator</a> <code>~</code>:</p>
<pre><code>{% set jsonData = fetchJson({
      'url': 'https://api.chucknorris.io/jokes&amp;keyword=' ~ field.name ~ '&amp;apikey=12345'
}) %}
</code></pre>
<p>Or if you prefer you can use <a href="https://twig.symfony.com/doc/1.x/templates.html#string-interpolation" rel="nofollow noreferrer">string interpolation</a> (note this <em>requires</em> double quote marks):</p>
<pre><code>{% set jsonData = fetchJson({
      'url': &quot;https://api.chucknorris.io/jokes&amp;keyword=#{field.name}&amp;apikey=12345&quot;
}) %}
</code></pre>

CC BY-SA 4.0
2022-10-12T12:21:35.280Z
2022-10-12T12:21:35.280Z
James Smith
<p>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.</p>
<p>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.</p>
<p>This is the idea of what I'm trying, based on the plugin's example code...</p>
<pre><code> {# Get a random Fact form chucknorris.io #}
    {% set jsonData = fetchJson({
      'url': 'https://api.chucknorris.io/jokes&amp;keyword={{ field.name }}&amp;apikey=12345'
    }) %}

    {% if (jsonData) %}
      &lt;h1&gt;Fact of the day&lt;/h1&gt;
      {{ 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! 
</code></pre>

<templating><plugins><url><json>
Field data as part of external URL call (jsonclient plugin)
# Field data as part of external URL call (jsonclient plugin)

(Asked by: username_0 on 2022-10-12)

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) %}
      Fact of the day
      {{ 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!

**Tags:** templating, plugins, url, json

---

## 1 answers

### Answer by username_1 on 2022-10-12. Score: 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"
}) %}


---

