title: TYPO3 7.6 get youtube-url from youtube-media-file for custom content element with fancybox
body: <p>if someone has a better title for my problem, go ahead and change it... ;-)</p>
  
  <p>I've been googling for quite a while but either I don't ask the right question or noone had struggles with this so far.</p>
  
  <p>I'm working with TYPO3 7.6, fancyBox v3.0.47 (<a href="http://fancyapps.com/fancybox/" rel="nofollow noreferrer">http://fancyapps.com/fancybox/</a>) and my own content element which I created for an image-gallery. So far so good. Everything worked fine until the customer asked to add video files to that gallery. The gallery uses fancyBox for the lightbox and I use it as follows:</p>
  
  <pre><code>&lt;div class="imgGalleryIMG"&gt;
    &lt;a href="/fileadmin{file.originalFile.identifier}" data-fancybox="gallery" data-caption="{file.description}"&gt;
      &lt;f:image image="{file}" crop="{file.crop}" /&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The link is needed for the fancybox and the image inside is the previewed image (that can be cropped).</p>
  
  <p>This works fine with images and I can change <code>&lt;f:image image="{file}"</code> to <code>&lt;f:media file="{file}" /&gt;</code> so that the youtube video which is loaded into the content element with "Add media from URL" is displayed and starts playing when clicking on it but this way the lightbox from fancyBox won't popup and it stays as small as the preview-image.</p>
  
  <p>I tried using a different approach and I got stuck with the youtube video. By using "Add media from URL" the video is being saved to the filelist as youtube-file (meaning it has the file-extension ".youtube") and it's title becomes the name of the file. When I use <code>&lt;f:debug&gt;</code> I can't find the real link (eg. <a href="https://www.youtube.com/watch?v=WEkSYw3o5is" rel="nofollow noreferrer">https://www.youtube.com/watch?v=WEkSYw3o5is</a>) nor the video id (eg. WEkSYw3o5is) to the youtube video. If I use the above approach that I use for the images, I have a preview-image of the video but when I click on it the lightbox opens and there's nothing else but the youtube-video-id displayed.</p>
  
  <p>2nd approach:</p>
  
  <pre><code>&lt;div class="imgGalleryIMG"&gt;
    &lt;f:if condition="{file.originalFile.properties.extension} == 'youtube'"&gt;
      &lt;f:then&gt;
        &lt;a href="{file.originalFile.identifier}" data-type="iframe" data-fancybox="gallery" data-caption="{file.description}"&gt;
          &lt;f:image image="{file}" /&gt;
        &lt;/a&gt;
      &lt;/f:then&gt;
      &lt;f:else&gt;
        &lt;a href="/fileadmin{file.originalFile.identifier}" data-fancybox="gallery" data-caption="{file.description}"&gt;
          &lt;f:image image="{file}" crop="{file.crop}" /&gt;
        &lt;/a&gt;
      &lt;/f:else&gt;
    &lt;/f:if&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If I'm correct what I need is the link to the youtube video for the link for fancybox as stated in it's documentation.</p>
  
  <p>What I really want is a display-image for the youtube-video, which on click will be revealed in the lightbox (without autoplay). How can I achieve this?</p>
  
  <p>I would favour a solution that works changing the template only.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>With the first approach after rendering and fancybox doing its magic the result looks as follows:</p>
  
  <pre><code>&lt;div class="fancybox-container fancybox-show-controls fancybox-show-infobar fancybox-show-buttons fancybox-container--ready fancybox-controls--canzoomIn" role="dialog" tabindex="-1" id="fancybox-container-1" style=""&gt;
    ...
    &lt;div class="fancybox-slider-wrap"&gt;
      &lt;div class="fancybox-slider" style="transform: translate(0px, 0px);"&gt;
        &lt;div class="fancybox-slide fancybox-slide--current fancybox-slide--image fancybox-slide--complete" style="transform: translate(0px, 0px);"&gt;
          &lt;div class="fancybox-placeholder" style="transform: translate(512px, 131px) scale(1, 1); width: 1024px; height: 767.94px; opacity: 1; transition: none;"&gt;
            &lt;img class="fancybox-image" src="/fileadmin/user_upload/pathToImg.jpg"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    ...
    &lt;/div&gt;
  ... 
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the lightbox code. The image-src is being taken from the link around the image in my first approach (not from the image-file). This is why I would like to get the youtube-url or the youtube-id into my partial with fluid.</p>
  
  <hr>
  
  <p><strong><em>SOLUTION</em></strong></p>
  
  <p>Thanks to minifranske I found an easy way to do it:</p>
  
  <pre><code>&lt;f:if condition="{file.originalFile.properties.extension} == 'youtube'"&gt;
    &lt;f:then&gt;
      &lt;a href="https://www.youtube.com/embed/{file.contents}" data-type="iframe" 
  data-fancybox="gallery" data-caption="{file.description}"&gt;
        &lt;f:image image="{file}" /&gt;
      &lt;/a&gt;
    &lt;/f:then&gt;
  </code></pre>
  
  <p>Thanks a lot! :)</p>