# Using a variable inside a function inside a shortcode

**URL:** <https://zola.discourse.group/t/using-a-variable-inside-a-function-inside-a-shortcode/1434>\
**Category:** Support\
**Created:** [August 29, 2022, 8:46pm UTC](https://zola.discourse.group/t/using-a-variable-inside-a-function-inside-a-shortcode/1434 "2022-08-29T20:46:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![last](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@last](https://zola.discourse.group/u/last)\
**Post date:** [August 29, 2022, 8:46pm UTC](https://zola.discourse.group/t/using-a-variable-inside-a-function-inside-a-shortcode/1434/1 "2022-08-29T20:46:40Z")

</div>

I have this shortcode:

```nohighlight
<div class="cover-image">
  <img src="{{ src }}"/>
  <p class="desc">
    {{ body }}
  </p>
</div>

```

I am calling the shortcode like this:

```auto
{% cover(src="/posts/justice.jpg") %}
No light can compare with the light of justice.
{% end %}

```

I want to include image processing in it, so that I can automatically process images passed in, so something like this:

```auto
<div class="cover-image">
  {% set image = resize_image(path=config.base_url ~ src, width=1200, height=700, op="fill", format="webp") %}
  <img src="{{ image }}"/>
  <p class="desc">
    {{ body }}
  </p>
</div>

```

Now I error with:

```nohighlight
Error: Reason: Failed to render cover shortcode
Error: Reason: Failed to render 'shortcodes/cover.html'
Error: Reason: Function call 'resize_image' failed
Error: Reason: `resize_image`: Cannot find file: http://127.0.0.1:1111/posts/justice.jpg

```

However when I click the file, it loads right fine in the browser. Any idea how I can do this?

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [August 30, 2022, 8:26am UTC](https://zola.discourse.group/t/using-a-variable-inside-a-function-inside-a-shortcode/1434/2 "2022-08-30T08:26:04Z")

</div>

2 issues with using `config.base_url ~ src` as path for resize\_image:

1. Shortcode happen before the image is copied to the public directory so it won’t be there
2. resize\_image expect a filepath and not a URL anyway so you need to point the shortcode to the on disk path

---

<div class="post-metadata">

**Author:** ![last](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@last](https://zola.discourse.group/u/last)\
**Post date:** [August 30, 2022, 1:57pm UTC](https://zola.discourse.group/t/using-a-variable-inside-a-function-inside-a-shortcode/1434/3 "2022-08-30T13:57:27Z")

</div>

It wasn’t working either with the `src` variable alone which held: “/posts/justice.jpg”, could you show me a working example?

With just src, the images do get processed, but they appear as [object] in the html. `image.path` did not work either. which raises another question, how would I log and debug what the image object is?

[I overlooked the docks showing image.url] Thanks for the help.

So the working code is:

```auto
<div class="cover-image">
  {% set image = resize_image(path=src, width=1200, height=700, op="fill", format="webp") %}
  <img src="{{ image.url }}"/>
  <p class="desc">
    {{ body }}
  </p>
</div>

```
