Docs: Fields and pictures
Fields and pictures
The page being shown: field, fieldRaw, hasField, boundFields, rows, related, pictures, picture, image and link.
field($key, $default = '') #
A field's value as text (E; M for a rich-text or HTML field). Empty if the Layout does not declare the field or a condition hides it.
<?= $this->field('intro') ?>
fieldRaw($key, $default = '') #
The same value, unescaped (P).
<meta name="x" content="<?= htmlspecialchars($this->fieldRaw('intro'), ENT_QUOTES, 'UTF-8') ?>">
hasField($key) #
Whether the Layout declares the field and it shows on this page.
<?php if ($this->hasField('intro')): ?><p><?= $this->field('intro') ?></p><?php endif; ?>
boundFields() #
The fields this page shows, as [key => type].
<?php foreach ($this->boundFields() as $key => $type): ?><!-- <?= $key ?> --><?php endforeach; ?>
rows($key) #
A taglist or multiselect as a list of strings, a repeater as rows, a gallery as {image, alt} rows (E).
<?php foreach ($this->rows('faq') as $r): ?><dt><?= $r['q'] ?></dt><dd><?= $r['a'] ?></dd><?php endforeach; ?>
related($key) #
A relation field's published targets as {id, title, url}, in the order the editor arranged them (E). A post shows once it is due.
<?php foreach ($this->related('see_also') as $r): ?><a href="<?= $r['url'] ?>"><?= $r['title'] ?></a><?php endforeach; ?>
pictures($key, $attrs = []) #
A gallery as a list of ready-made <picture> strings (M).
<?php foreach ($this->pictures('gallery', ['class' => 'tile']) as $p) { echo $p; } ?>
picture($source, $alt = '', $attrs = []) #
One image as <picture> markup with width and height (M). $source is an image field's key, or an item from pages(), page(), posts() or a gallery row. An address that is not a media-library file, a same-site /uploads/ path or an https address gives an empty string.
<?= $this->picture('cover', '', ['class' => 'hero']) ?>
image($source) #
{url, width, height, webp} for markup of your own, such as a CSS background (E), or null.
<?php $i = $this->image('cover'); ?>
<div style="background-image:url(<?= $i['url'] ?? '' ?>)"></div>
link($key) #
A URL field as an href (E). A scheme that could run script gives #. Any other field type gives an empty string.
<a href="<?= $this->link('cta_url') ?>">Get started</a>