contentURL better way


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

$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" />

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

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


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