Search code examples
typesmacrosvisiblekentico

Kentico8 - New boolean field in existing page type, default value not set


On our website we want to add a "Print" button on certain pages. My goal is to add a boolean field to the page type that let's you choose if you want the button on the page or not.

This all works fine with a little code in the 'visible' checkbox of the webpart containing the print button:

{% CurrentDocument["printbutton"]#%}

My problem is this:

pages of that type that already exist automatically get the print button, even tho the field default value is set to 'No'

If I check those pages in the 'pages' application, the checkbox is unchecked. When I save and submit the pages again, the print button is gone. But, as you might guess, i don't want to resubmit hundreds of pages...

It looks like pages that already exist have no value in the new boolean field, and therefor automatically resolve as visible.

Anyone a clue how to solve this?


Solution

  • When you initially added your field you should have marked the field as required AND set the default value to true. By default this would have set all the fields to true. Next, if you don't want to have a default value of true, just go back in and set it to false, all subsequent pages added will be false by default unless someone checks true.

    Another way to set these is to run a simple query against your custom page type's table and set that value. If you have workflow and/or versioning enabled, this gets a little tricky so not the first route I'd take but it's an option.