<p>You could write a module that adds a twig extension to return the value of src from the string. That way you get to utilise PHP as per <a href="https://stackoverflow.com/questions/17017684/how-to-get-url-from-the-iframe-using-php">https://stackoverflow.com/questions/17017684/how-to-get-url-from-the-iframe-using-php</a> to get the value.</p>

<p><a href="https://pluginfactory.io/" rel="nofollow noreferrer">https://pluginfactory.io/</a> is a good starting point for adding a module to Craft.</p>

<p>alternative very dirty approach: If the iframe markup is always going to be the same, you could do <code>|replace()</code>, replacing everything before the <code>src="</code> and everthing after the <code>" width</code> with empty strings. Then replace <code>" width</code> with an empty string.</p>

CC BY-SA 4.0
2019-03-13T13:35:06.817Z
Thank you @mijewe! Never built a plugin, but yes, it will always be generated iframe from a Pardot form every time. I think I will try and get the |replace to work.
mateostabio
CC BY-SA 4.0
2019-03-13T10:10:41.557Z
2019-03-13T10:10:41.557Z
mijewe
<p>I have have a text field for copy-pasting an iFrame code.</p>

<pre><code>&lt;iframe src="https://webpagelink.com/l/3556456/2019-03-06/34576" width="100%" 
height="500" type="text/html" frameborder="0" allowTransparency="true" 
style="border: 0"&gt;&lt;/iframe&gt;
</code></pre>

<p>What I need help with is striping out the URL within the <code>src=""</code> value from the iframe. Is this possible using Twig?</p>

<p>Thank you for your help!</p>

CC BY-SA 4.0
2019-03-12T23:16:59.997Z
Do you want to _remove_ the `src` attribute from the iframe HTML code, or do you want to strip everything _but_ the `src` attribute (e.g. end up with a variable containing the URL in the original `src` attribute)?
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2019-03-13T00:59:25.530Z
Yeah like Mats I'm curious what you're trying to achieve here...
Jalen Davenport
CC BY-SA 4.0
2019-03-14T15:08:51.230Z
@MatsMikkelRummelhoff - My client copy/pastes iframe codes in, and now we realized that I need to inject a variable with entry.title into the iframe. So yes, I just need to get the url only.
mateostabio
<templating><twigextension><plaintext>
How to strip out src="" value with twig from iframe code
# How to strip out src="" value with twig from iframe code

(Asked by: username_0 on 2019-03-12)

I have have a text field for copy-pasting an iFrame code.


What I need help with is striping out the URL within the src="" value from the iframe. Is this possible using Twig?
Thank you for your help!

**Tags:** templating, twigextension, plaintext

> **Comments:**
> **username_1**: Do you want to _remove_ the `src` attribute from the iframe HTML code, or do you want to strip everything _but_ the `src` attribute (e.g. end up with a variable containing the URL in the original `src` attribute)?  
> **username_2**: Yeah like Mats I'm curious what you're trying to achieve here...  
> **username_0**: @MatsMikkelRummelhoff - My client copy/pastes iframe codes in, and now we realized that I need to inject a variable with entry.title into the iframe. So yes, I just need to get the url only.  

---

## 1 answers

### Answer by username_3 on 2019-03-13. Score: 2 | Accepted answer

You could write a module that adds a twig extension to return the value of src from the string. That way you get to utilise PHP as per <https://stackoverflow.com/questions/17017684/how-to-get-url-from-the-iframe-using-php> to get the value.

<https://pluginfactory.io/> is a good starting point for adding a module to Craft.

alternative very dirty approach: If the iframe markup is always going to be the same, you could do `|replace()`, replacing everything before the `src="` and everthing after the `" width` with empty strings. Then replace `" width` with an empty string.

> **Comments:**
> **username_0**: Thank you @username_3! Never built a plugin, but yes, it will always be generated iframe from a Pardot form every time. I think I will try and get the |replace to work.  

---

