Related pages

Jan Willem Bergsma asked on October 17, 2016 10:57

Hi there,

I'm a newbie in Kentico and developing my first Kentico site. I'm running in a problem for which i can't find the answer.

I have a page type with 2 fields: Participants and OrganisingParticipants. Both fields are of data type "Pages". How can i access the information in this fields? I want to know which pages in field Participants and which pages in OrganisingParticipants.

I'm using the static HTML webpart to display the data. So far i only got the following code:

{% foreach (doc IN Documents[NodeAliasPath].RelatedDocuments.All) { Documents[doc.NodeAliasPath].GetValue("Logo"); } %}

This code returns all related pages. I only want the related pages of a specific field.

Thanks ina advance Regards Jan Willem

Correct Answer

Jan Hermann answered on October 17, 2016 11:33

Regrettably, macros are not prepared for such a task. When you add a Pages field a new ad-hoc relationship gets created with random GUID so it would be difficult to manage them via K#. We are working to make this more accessible in upcoming versions, but currently I would recommend to implement either custom transformation method (ASCX transformations) or custom macro method (Text/XML transformation) to access them.

https://www.kehrendev.com/blog/brenden-kehren/september-2015/display-related-documents-in-kentico-transformatio

0 votesVote for this answer Unmark Correct answer

Recent Answers


Jan Willem Bergsma answered on October 17, 2016 13:19

Hi Jan,

Thanks for your quick answer. I followed your instructions, but i can't get it working. What did i do:

  1. I created a custom transformation
  2. I creatted the transformation the webpart in the custom transformation uses
  3. I placed a repeater in the content zone and place the custom transformation in the transformation field

unfortunately there is no output. I know the transformation is working, because when i change the classname in custom transformation to a non-existing classname, the transformation crashes.

am i looking in the right direction?

Regards Jan Willem

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on October 17, 2016 13:50

What is the RelationshipName you are using in your code?

0 votesVote for this answer Mark as a Correct answer

Jan Willem Bergsma answered on October 17, 2016 15:38

Hi Jan,

ReleationShipName:isrelatedto. See code below

<script runat="server" type="text/javascript">
  protected override void OnInit(EventArgs e)
    {
      Guid guid = ValidationHelper.GetGuid(Eval("NodeGuid"), Guid.Empty);
      dlLocations.RelationshipWithNodeGuid = guid;
      dlLocations.ReloadData(true);
      base.OnInit(e);
    }
</script>
<h2>Test</h2>
<div class="row">
  <cms:CMSRepeater ID="dlLocations" runat="server" Path="/Partners/%" RelationshipName="isrelatedto" ClassNames="MySiteName.partner" TransformationName="MySiteName.event.EventDetail.Participants.List" />
</div>
0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on October 17, 2016 16:22 (last edited on October 17, 2016 16:22)

That's not correct. Pages field created randomly generated ad-hoc relationships. It should be something like custom.pagetype_846ca4e1-5d3f-46e4-99cd-af9afba173cb (CMS_RelationshipName)

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 17, 2016 22:23 (last edited on October 17, 2016 22:57)

If I understand you correctly, you can do the following:

You can create 2 different Relationship Types (aka RelationshipNames in Kentico language) smth like. "RelatedParticipants" and "RelatedOrginizingParicipants". Your current page will have bunch of related pages of these 2 types connected to it.

in the macro on this page you can do something like this: CurrentDocument.RelatedDocuments["RelatedParticipants"].WithAllData .ApplyTransformation("CMS.Root.MyParticipantsListing")

Create text/xml transfortmation MyParticipantsListing and you get values of the specific fields from "RelatedParticipants" and "RelatedOrginizingParicipants" documents simply using {%FieldName%}

P.S. WithAllData - can be quite slow depending on a number of relations defined .

0 votesVote for this answer Mark as a Correct answer

Jan Willem Bergsma answered on October 18, 2016 10:07

Hi Peter,

Thanks for your reply. I followed the solution of Jan.

@Jan: Thanks for the solution. It works!! I looked up the relationshipname in the table CMS_RelationshipName

Thanks again!

0 votesVote for this answer Mark as a Correct answer

Kevin O'Brien answered on November 4, 2016 00:08 (last edited on December 10, 2019 02:30)

On your custom page type try setting the field's data type to "text" and using the form control "Page Selector". This will allow only one page association per field and will store the GUID of the selected page. Then in a static text web part or any other macro field you can use this:

{%Documents.WithAllData.Where("NodeGUID='"+YourGuidFieldName+"'").FirstItem.DocumentName|(identity)GlobalAdministrator%}

if DocumentName works, you can replace it with you custom Logo field.

Note that this is dependent on page permissions, make sure the appropriate users have "Read" permission to the target page.

0 votesVote for this answer Mark as a Correct answer

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