<p>Try using:</p>

<pre><code>{{ gist.gistImage.first().getUrl('gistUnit')|replace({'http': 'https'}) }}
</code></pre>

CC BY-SA 3.0
2014-11-03T17:36:03.033Z
even better: `replace({'http://': 'https://'})` so you won't map `https://` to `httpss://`
Marion Newlevant
CC BY-SA 3.0
2014-11-03T04:01:25.440Z
2014-11-03T04:01:25.440Z
Brad Bell
<p>I have a template that displays in both http and https environments. When pulling my images for the https environment I need to be able to change the URL to https:// from http://. I tried</p>

<pre><code>{{ gist.gistImage.first().getUrl('gistUnit')|replace({'http': https}) }}
</code></pre>

<p>based on the documentation here twig.sensiolabs.org/doc/filters/replace.html</p>

<p>Not working. Is this because getURL() gets processed after the filter?</p>

<https>
Using Twig's replace filter with getURL()
# Using Twig's replace filter with getURL()

(Asked by: username_0 on 2014-11-03)

I have a template that displays in both http and https environments. When pulling my images for the https environment I need to be able to change the URL to https:// from http://. I tried
{{ gist.gistImage.first().getUrl('gistUnit')|replace({'http': https}) }}

based on the documentation here twig.sensiolabs.org/doc/filters/replace.html
Not working. Is this because getURL() gets processed after the filter?

**Tags:** https


---

## 1 answers

### Answer by username_1 on 2014-11-03. Score: 3 | Accepted answer

Try using:
{{ gist.gistImage.first().getUrl('gistUnit')|replace({'http': 'https'}) }}

> **Comments:**
> **username_2**: even better: `replace({'http://': 'https://'})` so you won't map `https://` to `httpss://`  

---

