contentURL better way

Hi!

I am working on a single page and use the following code:

<?php
$projects = page('projects')->children()->visible();
?>

<ul class="expanded row showcase">
  <?php foreach($projects as $project): ?>
    <div class="large-6 xxlarge-4 columns end">
      <li class="showcase-item">
      <div class="videocontainer">

          <video poster="<? echo $project->contentURL()?>/<?=  $project->poster() ?>">
            <source src="<? echo $project->contentURL()?>/<?=  $project->html5()?>" type="video/mp4" />
          </video>

      </div>
      <div class="tags">
        <?=  $project->tags() ?>
      </div>
      <div class="showcase-content">
      <h2 class="showcase-title"><?= $project->title()->html() ?></h3>
      <p class="showcase-text"><?= $project->text()->html() ?></p>
      </div>
    </li>
  </div>
  <?php endforeach ?>
</ul>

Is there a more elegant way to get the file URL in the video element?

Thanks

You can use the toFile() method:

<video poster="<?= $project->poster()->toFile()->url() ?>">

On a side note: It’s not recommended to use PHP short tags apart from the short echo tag (like in my example above)

1 Like