Answers.Body: <p>Asset fields return like an array so they can potentially have more than one item, you need to request the first item only with <code>.one()</code> (as opposed to requesting <code>.all()</code>)</p>
  <pre><code>//First check if the asset field has more than zero items
  {% if block.video.videoFileWebm|length %}
      // Retrieve the first and only item in the asset field
      &lt;source src=&quot;{{ block.video.videoFileWebm.one().url }}&quot; type=&quot;video/webm&quot;&gt;
  {% endif %}
  </code></pre>
  <p>I would also set <code>block.video</code> to a variable to clean up the code a bit and maybe speed it up a little.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T13:39:10.197Z
Answers.Text: It's not really accurate to say that "asset fields presume that you may have more than one item", it's more the case that element queries need to be _executed_ - whether that's `.one()` or `.all()` or `.ids()` or any of the other execution methods.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T13:53:08.687Z
Answers.Text: @JamesSmith you're right, that was badly written, updated!
Answers.UserDisplayName: dmatthams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T14:03:12.233Z
Answers.Text: Sorry for splitting hairs, but still not quite right - Calling an asset field without one of the execution methods will not return an array - it'll return an _element query object_: that query then needs to be executed before you can access the result - which in this case would be an Asset object.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T14:23:13.953Z
Answers.Text: Hey, I'm happy with it – it's easy to understand for all levels, but feel free to edit if you want.
Answers.UserDisplayName: dmatthams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T13:26:20.590Z
Answers.LastActivityDate: 2020-09-28T14:21:37.917Z
Answers.LastEditDate: 2020-09-28T14:21:37.917Z
Answers.UserDisplayName: dmatthams
Answers.Body: <p>You haven't executed your element queries. You'll need to call <code>.one()</code> on each related element, or, better, use eager loading to do the whole lot in one go:</p>
  <p>I've assumed in the example below that 'video' is an entry select field type inside a matrix block type called 'video' inside a matrix field called 'matrixBlocks':</p>
  <pre><code>{% set matrixBlocks = entry.matrixBlocks.with([    
      'video:video.videoThumbnail',
      'video:video.videoFileWebm',
      'video:video.videoFileOgg',
      'video:video.videoFileMp4',
  ]).all() %}
  
  {% for block in matrixBlocks %}
      {% if block.type == 'video' and block.video|length %}
          {% set videoEntry = block.video[0] %}
          &lt;video {{ videoEntry.videoAutoplay ? 'autoplay' }} {{ videoEntry.videoLoop ? 'loop'}}
              {% if videoEntry.videoThumbnail %}
                  {% set optimizedImages = videoEntry.videoThumbnail[0].imageVariants16by9 %}
                  poster=&quot;{{ optimizedImages.srcset() }}&quot;
              {% endif %} muted&gt;
  
              {% if videoEntry.videoFileWebm %}
                  &lt;source src=&quot;{{ videoEntry.videoFileWebm[0].url }}&quot; type=&quot;video/webm&quot;&gt;
              {% endif %}
              {% if videoEntry.videoFileOgg %}
                  &lt;source src=&quot;{{ videoEntry.videoFileOgg[0].url }}&quot; type=&quot;video/ogg&quot;&gt;
              {% endif %}
              {% if videoEntry.videoFileMp4 %}
                  &lt;source src=&quot;{{ videoEntry.videoFileMp4[0].url }}&quot; type=&quot;video/mp4&quot;&gt;
              {% endif %}
              
              &lt;p&gt;This browser does not support the video element.&lt;/p&gt;
          &lt;/video&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T15:41:43.223Z
Answers.LastActivityDate: 2020-09-28T15:41:43.223Z
Answers.UserDisplayName: James Smith
Body: <p>I'm trying to output the video files from within a block but get a <code>Calling unknown method: craft\elements\db\AssetQuery::url()</code> error when using the following:</p>
  <pre><code>{{ block.video.videoFileWebm.url }}
  </code></pre>
  <p>Assets in this volume have public URLs so I'm not sure why this isn't working.</p>
  <p><strong>FULL CODE</strong></p>
  <pre><code>{% if block.video %}
  
                  &lt;video {% if block.video.videoAutoplay %}autoplay{% endif %} {% if block.video.videoLoop %}loop{% endif %} 
                                                      
                      {% if block.video.videoThumbnail %}
                      {% set optimizedImages = block.video.videoThumbnail.one().imageVariants16by9 %}
                      poster=&quot;{{ optimizedImages.srcset() }}&quot;
                      {% endif %} muted&gt;
  
                      {% if block.video.videoFileWebm %}
                          &lt;source src=&quot;{{ block.video.videoFileWebm.url }}&quot; type=&quot;video/webm&quot;&gt;
                      {% endif %}
                      {% if block.video.videoFileOgg %}
                          &lt;source src=&quot;{{ block.video.videoFileOgg.url }}&quot; type=&quot;video/ogg&quot;&gt;
                      {% endif %}
                      {% if block.video.videoFileMp4 %}
                          &lt;source src=&quot;{{ block.video.videoFileMp4.url }}&quot; type=&quot;video/mp4&quot;&gt;
                      {% endif %}
                      
                      &lt;p&gt;This browser does not support the video element.&lt;/p&gt;
                  &lt;/video&gt;
  
              {% endif %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-09-28T13:00:07.947Z
Comments.Text: Just to clarify, is "video" a block type in a matrix, or is it a matrix field in an entry? I'm confused because you're doing `block.video` when it looks like you mean `entry.videoBlocks`, more specifically `entry.videoBlocks.one()`?
Comments.UserDisplayName: James Smith
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-09-28T15:30:05.047Z
Comments.Text: ...Or is "video" an entries select field in a matrix block? Either way you need to add some eager loading. Check your deprecation errors in Utilities and you'll see what needs fixing.
Comments.UserDisplayName: James Smith
Tags: <craft3><assets><video>
Title: Video Asset URLs not rendering
ThreadText: # Video Asset URLs not rendering
  
  (Asked by: username_0 on 2020-09-28)
  
  I'm trying to output the video files from within a block but get a `Calling unknown method: craft\elements\db\AssetQuery::url()` error when using the following:
  
  ```
  {{ block.video.videoFileWebm.url }}
  
  ```
  
  Assets in this volume have public URLs so I'm not sure why this isn't working.
  
  **FULL CODE**
  
  ```
  {% if block.video %}
  
                  <video {% if block.video.videoAutoplay %}autoplay{% endif %} {% if block.video.videoLoop %}loop{% endif %} 
                                                      
                      {% if block.video.videoThumbnail %}
                      {% set optimizedImages = block.video.videoThumbnail.one().imageVariants16by9 %}
                      poster="{{ optimizedImages.srcset() }}"
                      {% endif %} muted>
  
                      {% if block.video.videoFileWebm %}
                          <source src="{{ block.video.videoFileWebm.url }}" type="video/webm">
                      {% endif %}
                      {% if block.video.videoFileOgg %}
                          <source src="{{ block.video.videoFileOgg.url }}" type="video/ogg">
                      {% endif %}
                      {% if block.video.videoFileMp4 %}
                          <source src="{{ block.video.videoFileMp4.url }}" type="video/mp4">
                      {% endif %}
                      
                      <p>This browser does not support the video element.</p>
                  </video>
  
              {% endif %}
  
  ```
  
  **Tags:** craft3, assets, video
  
  > **Comments:**
  > **username_1**: Just to clarify, is "video" a block type in a matrix, or is it a matrix field in an entry? I'm confused because you're doing `block.video` when it looks like you mean `entry.videoBlocks`, more specifically `entry.videoBlocks.one()`?  
  > **username_1**: ...Or is "video" an entries select field in a matrix block? Either way you need to add some eager loading. Check your deprecation errors in Utilities and you'll see what needs fixing.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-09-28. Score: 3 | Accepted answer
  
  Asset fields return like an array so they can potentially have more than one item, you need to request the first item only with `.one()` (as opposed to requesting `.all()`)
  
  ```
  //First check if the asset field has more than zero items
  {% if block.video.videoFileWebm|length %}
      // Retrieve the first and only item in the asset field
      <source src="{{ block.video.videoFileWebm.one().url }}" type="video/webm">
  {% endif %}
  
  ```
  
  I would also set `block.video` to a variable to clean up the code a bit and maybe speed it up a little.
  
  > **Comments:**
  > **username_1**: It's not really accurate to say that "asset fields presume that you may have more than one item", it's more the case that element queries need to be _executed_ - whether that's `.one()` or `.all()` or `.ids()` or any of the other execution methods.  
  > **username_2**: @username_1 you're right, that was badly written, updated!  
  > **username_1**: Sorry for splitting hairs, but still not quite right - Calling an asset field without one of the execution methods will not return an array - it'll return an _element query object_: that query then needs to be executed before you can access the result - which in this case would be an Asset object.  
  > **username_2**: Hey, I'm happy with it – it's easy to understand for all levels, but feel free to edit if you want.  
  
  ---
  
  ### Answer by username_1 on 2020-09-28. Score: 0
  
  You haven't executed your element queries. You'll need to call `.one()` on each related element, or, better, use eager loading to do the whole lot in one go:
  
  I've assumed in the example below that 'video' is an entry select field type inside a matrix block type called 'video' inside a matrix field called 'matrixBlocks':
  
  ```
  {% set matrixBlocks = entry.matrixBlocks.with([    
      'video:video.videoThumbnail',
      'video:video.videoFileWebm',
      'video:video.videoFileOgg',
      'video:video.videoFileMp4',
  ]).all() %}
  
  {% for block in matrixBlocks %}
      {% if block.type == 'video' and block.video|length %}
          {% set videoEntry = block.video[0] %}
          <video {{ videoEntry.videoAutoplay ? 'autoplay' }} {{ videoEntry.videoLoop ? 'loop'}}
              {% if videoEntry.videoThumbnail %}
                  {% set optimizedImages = videoEntry.videoThumbnail[0].imageVariants16by9 %}
                  poster="{{ optimizedImages.srcset() }}"
              {% endif %} muted>
  
              {% if videoEntry.videoFileWebm %}
                  <source src="{{ videoEntry.videoFileWebm[0].url }}" type="video/webm">
              {% endif %}
              {% if videoEntry.videoFileOgg %}
                  <source src="{{ videoEntry.videoFileOgg[0].url }}" type="video/ogg">
              {% endif %}
              {% if videoEntry.videoFileMp4 %}
                  <source src="{{ videoEntry.videoFileMp4[0].url }}" type="video/mp4">
              {% endif %}
              
              <p>This browser does not support the video element.</p>
          </video>
      {% endif %}
  {% endfor %}
  
  ```
  
  
  ---
  
  