Assign an alternative form to document type

Keirei Yanagi asked on March 11, 2015 03:49

Hi! :)

I want to add some fields to the Form tab for one of the sites (for example, site A) to add a Preview Image URL field within our Kentico CMS, but it should not affect the form tab of the other documents in other sites (sites B to D).

I tried to edit the fields tab and the form of the Page document type and this worked however this also affected the other sites that also used the same document type so I decided to try using alternative forms. I've managed to create an alternative form for the default Page document type but now I'm not sure how to assign the alternative form to show only for Site A and not affect the others. (I'm hoping that this is possible without creating a new document type because there's already a lot of content using the Page document type.)

I appreciate all the help!

Recent Answers


Brenden Kehren answered on March 11, 2015 03:51

Set the visibility of the field based on the SiteName using a macro.

0 votesVote for this answer Mark as a Correct answer

Keirei Yanagi answered on March 11, 2015 03:56

Hi Brenden Kehren, :)

Sorry, can you tell me how I'll be able to implement this?

Thank you!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 11, 2015 04:13

You can add this to the Visibility property that you want to show for a specific site

SiteContext.CurrentSiteName == "SiteCodeName"

0 votesVote for this answer Mark as a Correct answer

Keirei Yanagi answered on March 11, 2015 05:52

Hi Brenden! :)

Sorry, I have another question. Where can I find the Visibility property? I'm a little worried that it's not available in the version of Kentico that I'm using (Kentico 5.5 R2)? Or I'm probably not looking in the right places.

Thanks!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 11, 2015 12:48

Unfortunately, the Visibility property isn't available in v5.5. You'd have to create a custom page for this and define the edit form within the doc types properties on the General tab. What this means is you'd create an alternative form (suggest 1 for each site), then create a physical page in the file system which would inherit the CMSDeskPage class (I believe). Then in the code behind load the object information and set the form definition to the alternative form for the site that is currently being accessed.

What I would do is create my alternative forms in a similar fashion so I don't have to hard code anything. For instance, if my site code name is MySite, I'd name my alternative form DocTypeEditMySite. Then in code, I can gather my alternative form by using form.AlternativeForm = "DocTypeEdit" + CurrentSite.SiteCodeName (which would render DocTypeEditMySite).

All the code is psudo, so you'd have to see what it actually would look like for the version you are on. I'd suggest looking in the file system in the /CMSModules/DocumentTypes/Pages to start, there should be some examples of how you'd get started in there. Remember to create your own set of pages though, don't modify the base ones.

0 votesVote for this answer Mark as a Correct answer

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