Changing page templates in the database

James Renshaw asked on June 11, 2019 15:24


We run Kentico 10, and are still on the Portal Engine. We want to be able to switch to a black and white version of our site for special event and then switch back again. We want to do this across the entire site, and do it with minimal effort. I've created a style sheet and some extra JavaScript for this, and it works well.

I cloned the current templates we use, and added the style sheets to the header, and the JavaScript just before the body tag (as they were required to be there to work properly). I did some research on the best way to change the site, and found that the database could be edited, specifically the 'DocumentPageTemplateId' column in the 'CMS_Document' table needed changing from it's current value, to the new template's id.

I ran query to do this on all of the pages, so that each template, was changed to the corresponding black and white template. For all the standard pages, this worked fine, however for any different page types (e.g. News or Blog Post) this doesn't seem to work. The id in the column has changed, but in the Kentico dashboard, it shows that it is still the old template. Annoyingly, if I change it in the Kentico dashboard, it then works, even updating the database id if I change it back.

It's definitely something to do with the page type, as making the news page or blog post type 'Behave as menu item' in properties makes it work. This however causes issues with the layout and would require a lot of work to sort out, so isn't an option. Is there anything I'm missing? Or is this a bug?

Any help would be appreciated.

Correct Answer

Dmitry Bastron answered on June 12, 2019 12:29

Hi James,

You can also check the setting in the Kentico admin (All culture versions use the same page template):

Image Text

If it is enabled the system then uses different setting stored in CMS_Tree instead:

  • [NodeTemplateID]: id of the template assigned for the Node (for all culture versions)
  • [NodeTemplateForAllCultures]: when this equals 1 it means that All culture versions use the same page template and the setting above is used instead of DocumentPageTemplateId from CMS_Document table.
0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on June 11, 2019 16:40

Typically this happens becuase you have workflow and/or versioning enabled. Because of this your best bet is to create an api call, check the page out, update the template ID, check the page back in and publish it. This will update the workflow/version you need vs. just the CMS_Document table which is what you're currently doing.

Another option is to remove all the documents from workflow/versioning and apply your change, then add those pages back into workflow again.

0 votesVote for this answer Mark as a Correct answer

James Renshaw answered on June 12, 2019 14:10

Hi Dmitry, thanks, that was the one. Interestingly that option doesn't appear under templates for me, but it's on in the database. I'll apply the change under that column as well for future updates.

Thanks also to Brenden, although using API didn't help (it still didn't update the template when checking in, out and publishing), it did allow me to play with the API which will likely be useful in the future.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.