Timbob
Timbob

Reputation: 5

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?

Upvotes: 0

Views: 359

Answers (2)

Martin Makarsky
Martin Makarsky

Reputation: 2650

I am not sure I understand your problem but in context of your last sentence:

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

There is default value you can set per each field, so you can set default value for your new boolean field. enter image description here

Upvotes: 2

Brenden Kehren
Brenden Kehren

Reputation: 6117

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.

Upvotes: 1

Related Questions