Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Content & Markdown

"> after using an audio tag

Solved by pamtbaau View solution

Started by Joel Castillo Guerra 6 years ago · 3 replies · 708 views
6 years ago

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:

TWIG
{% 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:

TXT
<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!

last edited 03/27/20 by Joel Castillo Guerra
6 years ago

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

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

</pre>

6 years ago Solution

@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

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 99 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 186 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 148 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 62 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 257 1 year ago