Toggle - add a class

In my Blueprint I have a Toggle field:

display_info:
	label: Display info?
	type: toggle
	text: 
		- "No"
		- "Yes"

In my template I have the following code.

<div class="<?php e($page->display_info()->toBool() === false, 'do-not-display') ?>">

Is this saying: if the “display_info” field equals “false” add the class “do-not-display”?

And presumably if the display_info is set to “true” no class is added?

This looks a lot simpler:

<div class="<?= $page->display_info() ?>">

It adds the class true or false, which I can then use in the CSS

Three months from now, you will wonder what those classes mean.

1 Like

Yeah, I was thinking that!

I’ve added a class info-box to the div, so then in my CSS I can write

.info-box.false {
	display: none;
}

A little crude but at least I understand the template PHP code

I think it’s time to learn some PHP basics, like if statements. they are no mystery, after all, you use conditions in everyday talk all the time, like “If it snows tomorrow, I’ll go sledging.”

I would reccomend NetNinja on youtube that has alot of free video courses on alot of web technologies, including PHP. (look in the playlists)

Hey thanks for the recommendation