# Error within conditional even when conditional should not run

**URL:** <https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384>\
**Category:** Uncategorized\
**Created:** [April 4, 2018, 10:47pm UTC](https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384 "2018-04-04T22:47:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davehlewis](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@davehlewis](https://discourse.gohugo.io/u/davehlewis)\
**Post date:** [April 4, 2018, 10:47pm UTC](https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384/1 "2018-04-04T22:47:08Z")

</div>

I have an error in an if that I use to check if an image url has been set. I’m getting an error when running as Hugo seems to parse the content of the if, even when it should ignore it.

```
{{ if and (isset .Params "imageurl") (not (eq .Params.imageurl "")) }}
  {{ $image_path := substr .Params.imageurl 0 -4 }}
  {{ $image_path }}
{{ end }}

```

I assume this is a nuance of the templating system, and might just be how it works, but am I missing something? Is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![davehlewis](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@davehlewis](https://discourse.gohugo.io/u/davehlewis)\
**Post date:** [April 11, 2018, 11:03am UTC](https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384/2 "2018-04-11T11:03:13Z")

</div>

Does no one have anything to say on this? If more information is needed, please let me know.

---

<div class="post-metadata">

**Author:** ![RickCogley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rickcogley/32/10269_2.png) [@RickCogley](https://discourse.gohugo.io/u/RickCogley)\
**Post date:** [April 11, 2018, 11:06am UTC](https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384/3 "2018-04-11T11:06:51Z")

</div>

The `with` function is similar to if, but does not fail if the param is unset. You might try that.

When you run your `hugo server` try it with the `--verbose` switch to see what’s going on. It would help if you could report the error you see there.

---

<div class="post-metadata">

**Author:** ![davehlewis](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@davehlewis](https://discourse.gohugo.io/u/davehlewis)\
**Post date:** [April 11, 2018, 11:11am UTC](https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384/4 "2018-04-11T11:11:18Z")

</div>

Thanks Rick, with have a look at that.

---

<div class="post-metadata">

**Author:** ![RickCogley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rickcogley/32/10269_2.png) [@RickCogley](https://discourse.gohugo.io/u/RickCogley)\
**Post date:** [April 11, 2018, 11:17am UTC](https://discourse.gohugo.io/t/error-within-conditional-even-when-conditional-should-not-run/11384/5 "2018-04-11T11:17:31Z")

</div>

This is it:

> **[with](https://gohugo.io/functions/with#readout)**
>
> Rebinds the context (\`.\`) within its scope and skips the block if the variable is absent.

Untested but something like:

```auto
{{ with .Params.imageurl }}
{{ $image_path := sub...
...
{{ end }}

```
