"> after using an audio tag

Hey there,
I’ve got a question about using for loops and audio tags. The website I’m making has different pages, each page containing it’s own audio file. For every page I want to make the audio file playable. I’ve done this by using the following code:

{% for filename, song in page.media %}
      {% if filename ends with '.m4a' %}
      <audio controls>
        <source src="{{ page.media[filename] }}">
      </audio>
      {% endif %}
{% endfor %}

But everytime I do this, the final page renders a "> after the closing audio tag:

<audio controls>
<source src="[<audio controls=](http://localhost/books/%3Caudio%20controls=)"1" alt=""><source src="[/user/pages/03.books/01.song.m4a]z(http://localhost/user/pages/03.books/01.Stip-leert-vliegen/stip-leert-vliegen-liedje.m4a)">Your browser does not support the audio tag.</audio>">
</audio>

Can someone help me get rid of this?

I’m currently using Grav v1.6.23

Thanks for the help!

@joelcastillo, To properly show what your code looks like, you’ll need to format the Twig code using tripple backticks (```).

 
```
{% for filename, song in page.media %}
   {% if filename ends with '.m4a' %}
     // My audo code
   {% endif %}
{% endfor %}
```

Thank you! I’ve changed it.

@joelcastillo, You are assigning a media object to src instead of the url of the media object.

Try <source src="{{ page.media[filename].url }}">

1 Like