Add fields to Site class

Tom Troughton asked on March 11, 2015 16:13

I'm building a site where I'd like to customise the Site class in the CMS module to add some fields. One example, this is a multisite where some sites represent countries, others brands. For navigation purposes I need to distinguish between these. Ideally I'd add additional fields to the Site class in CMS but this class is not customisable. What are my options?


Correct Answer

Brenden Kehren answered on March 12, 2015 00:49

The quickest and easiest way would be something I'd probably do only if in a scenario like this. Otherwise I'd use a custom table or module.

You can modify that module directly in the database so you can edit those classes. By doing this you can then add the field through the UI and which will then show that field on the form.

Start by opening the Modules app. Then run this T-SQL code to find your CMS module ID:

select *
from CMS_Resource
where ResourceName like 'cms'

Then run this update statement to set the development mode to allow you to make changes:

update CMS_Resource
set ResourceIsInDevelopment = 1
where resourceid = YourIdYouRetrievedInThePreviousStatement

Then clear the cache on your site in the System module. Next add the field to the Site class and save it. Run the last T-SQL statement and set the ResourceIsInDevelopment = 0.

Now you've added your custom site field and the module's security is set back so others can't modify it.

Again, for something very simple and straightforward like you're looking for, this works, otherwise I'd recommend a custom table or a module.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Virgil Carroll answered on March 11, 2015 17:57

Can ou provide a little more information about why you need to do this? You said You end to do it for multi sites, but why do you need the additional fields. How are you structuring your sites that you cannot ell the difference through the hierarchy or by data set at the parent level?

A little more info and we might be able to help better. Thanks.

0 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on March 12, 2015 16:59

Thank you both for your answers.

Virgil, to clarify I basically want a simple way to query my sites to return a subset based on a custom boolean property of those sites. Can you explain what you mean by "data set at the parent level"? Do you mean at master page level? If I can configure each site to have certain boolean properties I don't mind where it occurs, but I'm not clear how I'd do what you suggest.

Brenden, I can see how your answer would work, although I'm concerned if may affect future upgrades?

Would you be so kind as to briefly explain how you might use a custom table? Do you mean define a custom table with a 1-to-1 relationship between its records and my sites?

0 votesVote for this answer Mark as a Correct answer

Filip Ligač answered on April 13, 2015 12:19

Hello Nat,

Basically Brenden's advice seems like the best one for a scenario you are describing. If you do not modify any built-in fields in the Site class but only add a few new fields, you should be safe as far as future upgrades are concerned.

In case of any more extensive changes, custom tables should be a way to go and setting up 1-to-1 or N-to-M relationships (depending on your needs) between records in the custom table and site-specific data is another way how to achieve it.

Best regards,

0 votesVote for this answer Mark as a Correct answer

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