Hello!
How can i get an image url from custom field with Page Builder!
I have text file with this structure:
Builder:
-
page_cover: 004.jpg
page_video_cover: ""
_fieldset: page_cover
And i want display a cover image directly in this page. I write this code:
<?php echo $page->builder()->toStructure()->page_cover()->toFile()->url() ?>
But this method did not work.
I want display just one image, without “foreach” method.
What code is correct in this situation ?
Thank You!
texnixe
2
Accoding to the readme, you should have a foreach loop that calls a snippet for each section like this:
<?php foreach($page->builder()->toStructure() as $section): ?>
<?php snippet( snippet('sections/' . $section->_fieldset(), array('section' => $section)) ) ?>
<?php endforeach ?>
And then in the page-cover snippet for the image part:
<a href="<?php echo $section->url() ?>">
<img src="<?php echo $section->page_cover()->toFile()->url() ?>" alt="section image">
</a>
Yeah, i know this method. But is it possible to show one image without loop?