Skip to main content
added 4 characters in body
Source Link
dmatthams
  • 2.5k
  • 11
  • 19

You're close!

Because an asset field can potentially contain multiple items you need to explicitly select the first one, so:

{% set video = component.video.one() %}

But that doesn't get the actual url of the video, to get that you need to request it:

{{ video.url() }}

So in your case:

{% set video = component.video.one() %}
{% if video %}
   <video width="800" height="500" controls>
      <source src="{{ video.url() }}" type="video/mp4">
   </video>
{% endif %}

If you do find yourself needing to show multiple files, then youyou'd wrap it withwithin a loop:

{# Get all the files #}
{% set videos = component.video.all() %}

{# Check to see if videos has anything in it with '|length' #}
{% if videos|length %}
    {% for video in videos %}
       <video width="800" height="500" controls>
          <source src="{{ video.url() }}" type="video/mp4">
       </video>
    {% endfor %}
{% endif %}

You're close!

Because an asset field can potentially contain multiple items you need to explicitly select the first one, so:

{% set video = component.video.one() %}

But that doesn't get the actual url of the video, to get that you need to request it:

{{ video.url() }}

So in your case:

{% set video = component.video.one() %}
{% if video %}
   <video width="800" height="500" controls>
      <source src="{{ video.url() }}" type="video/mp4">
   </video>
{% endif %}

If you do find yourself needing to show multiple files, then you wrap it with a loop:

{# Get all the files #}
{% set videos = component.video.all() %}

{# Check to see if videos has anything in it with '|length' #}
{% if videos|length %}
    {% for video in videos %}
       <video width="800" height="500" controls>
          <source src="{{ video.url() }}" type="video/mp4">
       </video>
    {% endfor %}
{% endif %}

You're close!

Because an asset field can potentially contain multiple items you need to explicitly select the first one, so:

{% set video = component.video.one() %}

But that doesn't get the actual url of the video, to get that you need to request it:

{{ video.url() }}

So in your case:

{% set video = component.video.one() %}
{% if video %}
   <video width="800" height="500" controls>
      <source src="{{ video.url() }}" type="video/mp4">
   </video>
{% endif %}

If you do find yourself needing to show multiple files, then you'd wrap it within a loop:

{# Get all the files #}
{% set videos = component.video.all() %}

{# Check to see if videos has anything in it with '|length' #}
{% if videos|length %}
    {% for video in videos %}
       <video width="800" height="500" controls>
          <source src="{{ video.url() }}" type="video/mp4">
       </video>
    {% endfor %}
{% endif %}
Source Link
dmatthams
  • 2.5k
  • 11
  • 19

You're close!

Because an asset field can potentially contain multiple items you need to explicitly select the first one, so:

{% set video = component.video.one() %}

But that doesn't get the actual url of the video, to get that you need to request it:

{{ video.url() }}

So in your case:

{% set video = component.video.one() %}
{% if video %}
   <video width="800" height="500" controls>
      <source src="{{ video.url() }}" type="video/mp4">
   </video>
{% endif %}

If you do find yourself needing to show multiple files, then you wrap it with a loop:

{# Get all the files #}
{% set videos = component.video.all() %}

{# Check to see if videos has anything in it with '|length' #}
{% if videos|length %}
    {% for video in videos %}
       <video width="800" height="500" controls>
          <source src="{{ video.url() }}" type="video/mp4">
       </video>
    {% endfor %}
{% endif %}