johan
December 6, 2019, 9:01am
#1
Hi,
Currently I have something like this:
<section class="bg-color-<?= $background->color()->value() ?> padding">
But I’ve started to improve my workflow by working with variables when the logic is a little more complex, to later on echo the final variable into the file:
if ($layout && $layout->fullScreen()->bool()) {
$primary_class = 'full-screen';
}
<section class="<?php echo $primary_class; ?>">
How can I output a value from a field inside a variable? Something like this
$primary_class = 'bg-color-'echo $background->color()->value()' padding';
texnixe
December 6, 2019, 9:08am
#2
You have to concatenate the strings and the field value with .
. Don’t echo anything here.
$primary_class = 'bg-color-' . $background->color()->value() . ' padding';
Make sure that there is a background color available.
What is $layout
, btw. a page?
It might be useful to put the logic into a controller .
1 Like
You can also use Heredoc which makes it much more readable if its quite a bit of stuff.
1 Like
johan
December 6, 2019, 9:14am
#4
Awesome!
$layout is a structure field:
$layout = $page->layoutHero()->toStructure()->first();