Link pages types using field

Sylvain C. asked on June 15, 2019 02:47

Following the Medioclinic example, I have built a small website which shows the list of doctors and the list of offices.

I have then 2 page types (OfficeItem and DoctorItem). I would like to associate for each doctor, the office where he works. It means that if a new office item is added, it would appear in the list of offices available for a new doctor item.

How can I have a field in my DoctorItem page type which is linked to my list of office items already entered. What is the way of doing so in the Admin site?

Thank you


Recent Answers

Mike Wills answered on June 15, 2019 05:30

Hi Sylvain,

There's a few options.

  • You could use the content tree. So that doctor's are hierarchically under offices. Then on an office page, you could query all the doctors under it. If a doctor can be in more than one office, you could use linked pages to create a link of the doctor page under each office for which he/she belongs. To display a list of offices for which the doctor belongs, you could use the search index to display the parent office pages found for the doctor page.

  • You could also use related pages. Check out the "Related pages" field control. However, be aware that the relationships defined in this field do not participate in document workflow. Such changes will take effect immediately, regardless of the publish status of the page.

  • You could also use the "Object selector" field control to store a delimited list of document guids in the field. This would allow you to provide a field on the doctor form, in which users can pick office pages. The DocumentGuid for the selected office pages would be stored in the field. To display the offices, you would have to parse the semi-colon delimited list of guids, and query the office pages having those guids. If the code name of your OfficeItem is "Sylvain.OfficeItem" the configuration of this control would look like this:

Object type: CMS.Document Return column name: DocumentGuid Display name format: {%DocumentName%} Selection mode: Multiple Where condition: ClassName = 'Sylvain.OfficeItem'

Let me know how it goes.



0 votesVote for this answer Mark as a Correct answer

Sylvain C. answered on June 17, 2019 08:16 (last edited on June 17, 2019 08:28)

Hello Mike,

Thnak you for your answer. I don't really see how my content editor, using the admin site, could use the content tree to choose an office for a new doctor she's adding. The idea would be while she creates a new doctor Item page, to have a dropdownlist with all the potential locations available.

I also tried to explore the "related pages" field control but when I change the form control of my new field to "related pages", there is no option available... Is there additional steps to consider in order to make this join between 2 pages types to work using this method?

Finally, I tried the Object selector and it worked using your syntax. However, it is quite obscure still, is there some documentation on it? I was more expecting a syntax similar to custom table where I would have chosen the page type for example (Sylvain.OfficeItem) and then the primary key and the column to display. Is there a way of doing so?

Finally why using CMS.Document for the object selector and not the page type directly?

For example, to ease the work of the content editor, I would like to show in my dropdown list of offices, only the offices for a which a field has a specific value such as "WHERE IsReviewed=true". Is it possible with Object selector? Would there be any option for achieving this simple need?

Sorry for all these questions but I really want to dig into it to better understand.


0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 18, 2019 15:32

To elaborate a bit more on what Mike stated. I'd highly recommend against using a 1 to 1 relationship (object selector) because we all know there will be that one instance where 1 doctor will work at multiple clinics.

Look at this a little different way and ask yourself a couple questions:

  1. Do the users need to navigate to /office-1/doctor-1?
  2. Can the doctor work at more than one office?

Typically for something like this, if the doctor can work at more than one office, we will place those doctors in a separate folder in the root of the content tree and call the folder /doctors. If they will always be specific to that office, then place them directly under the office in a /doctors folder.

If they are working at more than one office, you have 2 options:

  • linked pages - creates a reference to that doctor in another location, creates URL sructure so you can actually navigate to that doctor, allows you to update that doctor's information in one place and have it replicated to all other instances.
  • related pages - creates a simpile relationship between an office and a doctor.

If you need the doctor to have a physical page below the office, then use linked pages. If there is no need to have a page below the office, then use related pages. With related pages, you create a new relationship called "has this doctor". Then you go to an office and select Properties > Related pages and add a new relationship. Select the "has this doctor" relationship and in the right side, select the doctor which work at to that office. Do this for every doctor.

Use a repeater to display the doctors on the page. Select the path of /doctors, under Relationship select "Display pages related to the current page" and check the box for "Main page is on the left side", finally select the "has this doctor" relationship name. Add your transformation information for the doctor page type and save it. This will display your doctors related to that location.

Using a linked page, I didn't provide the details on that as they are just like getting the info from the regular place in the content tree. Only thing different is you might want to use GetDocumentUrl(Eval<int>("DocumentID")) as the method that retrieves the URL for the document.

1 votesVote for this answer Mark as a Correct answer

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