Answers.Body: <p>You need to define your assets, if the asset field is named <code>videoEmbed</code> in your matrix <code>matrixFieldHandle</code> you would loop through the matrix and grab the first asset with:</p>
  
  <pre><code>{% for block in entry.matrixFieldHandle %}
  
    {% set asset = block.videoEmbed.first() %}
  
    {% set embed = craft.embeddedAssets.fromAsset(asset) %}
  
    {% if embed %}
      {{ embed.safeHtml|raw }}
    {% endif %}
  
  {% endfor %}
  </code></pre>
  
  <p>You can find additional information about matrix-fields and templating here: <a href="https://craftcms.com/docs/matrix-fields#templating" rel="nofollow noreferrer">https://craftcms.com/docs/matrix-fields#templating</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-30T19:58:20.053Z
Answers.Text: This kinda worked and kinda didn‘t. It displayed the embedded video! That was a great moment to see it work he first time since 3 days. 
  
  But I could only add 1 entry in that matrix field. The moment I added a text block or an image to the entry I got a lot of frightening errors.
  
  So I guessed it might have something to do with the "(first)"-thing in the loop, since it feels like a "1" thing.
  
  So I changed the code to an if statement. Et voilà!
Answers.UserDisplayName: J.Zander
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-30T16:07:14.927Z
Answers.LastActivityDate: 2017-12-30T16:14:59.633Z
Answers.LastEditDate: 2017-12-30T16:14:59.633Z
Answers.UserDisplayName: HendrikEng
Answers.Body: <p>Just to wrap it up:</p>
  
  <p>I have a martix field for blog entries with the handle <code>blogBody</code> with a rich text block and several image blocks for different styled images.</p>
  
  <p>Here is the solution:</p>
  
  <p>I added a block to the matrix field with the handle <code>blogBody</code>, that has the handle <code>embedVideo</code>. The corresponding field is also called <code>embedVideo</code>.</p>
  
  <p>In the template I added to the block with the handle <code>blogBody</code> this code:</p>
  
  <pre><code>    {% if block.type == "embedVideo" %}
          {% set asset = block.embedVideo.first() %}
          {% set embed = craft.embeddedAssets.fromAsset(asset) %}
              {% if embed %}
              &lt;div id="video-box" class="videobox"&gt;
                    {{ embed.safeHtml|raw }}
              &lt;/div&gt;
              {% endif %}
      {% endif %}
  </code></pre>
  
  <p>Works.</p>
  
  <p>I also needed some responsiveness for the embedded video and used good "<a href="http://fitvidsjs.com" rel="nofollow noreferrer">FitVids</a>". So I wrapped the thing for the output in a div with a corresponding ID to FitVids and added a little bit of styling to the video wrapper using the class.</p>
  
  <p>Nice.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-30T20:13:20.110Z
Answers.LastActivityDate: 2017-12-30T20:13:20.110Z
Answers.UserDisplayName: J.Zander
Body: <p>I'm trying to use the "<a href="https://github.com/benjamminf/craft-embedded-assets" rel="nofollow noreferrer">Embedded Assets</a>" Craft plug-in to embed Youtube and Vimeo videos in a matrix field, but I can't figure it out. I've read through the instructions on the Github page but I can't make sense of it.</p>
  
  <p>I have successfully installed the plug-in, and it seems to be "grabbing" the videos correctly since I can see the video in the assets section and the json files are in the folder on my disk.</p>
  
  <p>I put this twig code from the instructions of the plugin provider in my template:</p>
  
  <pre><code>{% for asset in assets %}
      {% set embed = craft.embeddedAssets.fromAsset(asset) %}
      {% if embed %}
          {{ embed.safeHtml|raw }}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>but it breaks my page. </p>
  
  <p>This is the error message I get, saying the variable "assets" does not exist:</p>
  
  <pre><code>52         &lt;div class="video"&gt;
  53                 {% for videoEmbed in videoEmbed %}
  54                     {% set embed = craft.embeddedAssets.entry.    (videoEmbed) %}
  55                     {% if embed %}
  56                     {{ embed.safeHtml|raw }}
  57                     {% endif %}
  58                 {% endfor %}
  59                 {% endif %}
  60 
  61         &lt;/div&gt;
  62 
  63             
  64         {% endfor %}
  </code></pre>
  
  <p>I work locally and have dev mode turned on.</p>
  
  <p>I am trying to use the plugin inside a matrix field with "videoEmbed" as block and field handle.</p>
  
  <p>I created an asset source/ folder called "videos".</p>
  
  <p>And I am on the personal licence.</p>
  
Tags: <templating>
Title: Using embedded assets plugin to display youtube or vimeo embed urls on a template
ThreadText: # Using embedded assets plugin to display youtube or vimeo embed urls on a template
  
  (Asked by: username_0 on 2017-12-30)
  
  I'm trying to use the "[Embedded Assets](https://github.com/benjamminf/craft-embedded-assets)" Craft plug-in to embed Youtube and Vimeo videos in a matrix field, but I can't figure it out. I've read through the instructions on the Github page but I can't make sense of it.
  
  I have successfully installed the plug-in, and it seems to be "grabbing" the videos correctly since I can see the video in the assets section and the json files are in the folder on my disk.
  
  I put this twig code from the instructions of the plugin provider in my template:
  
  ```
  {% for asset in assets %}
      {% set embed = craft.embeddedAssets.fromAsset(asset) %}
      {% if embed %}
          {{ embed.safeHtml|raw }}
      {% endif %}
  {% endfor %}
  
  ```
  
  but it breaks my page.
  
  This is the error message I get, saying the variable "assets" does not exist:
  
  ```
  52         <div class="video">
  53                 {% for videoEmbed in videoEmbed %}
  54                     {% set embed = craft.embeddedAssets.entry.    (videoEmbed) %}
  55                     {% if embed %}
  56                     {{ embed.safeHtml|raw }}
  57                     {% endif %}
  58                 {% endfor %}
  59                 {% endif %}
  60 
  61         </div>
  62 
  63             
  64         {% endfor %}
  
  ```
  
  I work locally and have dev mode turned on.
  
  I am trying to use the plugin inside a matrix field with "videoEmbed" as block and field handle.
  
  I created an asset source/ folder called "videos".
  
  And I am on the personal licence.
  
  **Tags:** templating
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-12-30. Score: 3 | Accepted answer
  
  You need to define your assets, if the asset field is named `videoEmbed` in your matrix `matrixFieldHandle` you would loop through the matrix and grab the first asset with:
  
  ```
  {% for block in entry.matrixFieldHandle %}
  
    {% set asset = block.videoEmbed.first() %}
  
    {% set embed = craft.embeddedAssets.fromAsset(asset) %}
  
    {% if embed %}
      {{ embed.safeHtml|raw }}
    {% endif %}
  
  {% endfor %}
  
  ```
  
  You can find additional information about matrix-fields and templating here: <https://craftcms.com/docs/matrix-fields#templating>
  
  > **Comments:**
  > **username_0**: This kinda worked and kinda didn‘t. It displayed the embedded video! That was a great moment to see it work he first time since 3 days.   But I could only add 1 entry in that matrix field. The moment I added a text block or an image to the entry I got a lot of frightening errors.  So I guessed it might have something to do with the "(first)"-thing in the loop, since it feels like a "1" thing.  So I changed the code to an if statement. Et voilà!  
  
  ---
  
  ### Answer by username_0 on 2017-12-30. Score: 4
  
  Just to wrap it up:
  
  I have a martix field for blog entries with the handle `blogBody` with a rich text block and several image blocks for different styled images.
  
  Here is the solution:
  
  I added a block to the matrix field with the handle `blogBody`, that has the handle `embedVideo`. The corresponding field is also called `embedVideo`.
  
  In the template I added to the block with the handle `blogBody` this code:
  
  ```
      {% if block.type == "embedVideo" %}
          {% set asset = block.embedVideo.first() %}
          {% set embed = craft.embeddedAssets.fromAsset(asset) %}
              {% if embed %}
              <div id="video-box" class="videobox">
                    {{ embed.safeHtml|raw }}
              </div>
              {% endif %}
      {% endif %}
  
  ```
  
  Works.
  
  I also needed some responsiveness for the embedded video and used good "[FitVids](http://fitvidsjs.com)". So I wrapped the thing for the output in a div with a corresponding ID to FitVids and added a little bit of styling to the video wrapper using the class.
  
  Nice.
  
  
  ---
  
  