Thread tagged as: Question, Problem

Custom Page attribute

Hi, I have successfully set up a custom 'select' perch page attribute which selects a light or dark theme for the page:

In default.html:

<perch:pages id="bodyclass" type="select" label="Page look" options="Dark, Light" suppress="true" help="Decide if elements on the page will look Dark or Light. Change this if your header navigation isn't very clear."/>

In my php template:

<body class="<?php perch_page_attribute('bodyclass', array('template'=>'bodyclass.html')); ?>">

Here is the template bodyclass.html:

<perch:pages id="bodyclass" type="select" label="Page look" options="Light, Dark"/>

It works well, except when I create a new page, Light isn't selected so therefore not injected into the body class as a default value. This plays havoc with the layout as I am trying to hook into this class. Is there a way to force the value to be injected into the template upon saving the new page?


Adam Menczykowski

Adam Menczykowski 1 points

  • 5 years ago

I have to go to the Page details, then save for the value to 'kick in'.

Drew McLellan

Drew McLellan 2638 points
Perch Support


<perch:pages id="bodyclass" type="select" label="Page look" options="Light, Dark" else="Light" />

A ha! Thank you Drew.