ascx transformation relationship conditional statement

kyle shapiro asked on December 14, 2015 22:10

Hello DevNet, In an ascx transformation I have under one of my repeaters, I would like to check for if that repeated item is in a specific relationship, and display something if that's true. Digging through the API, I found CMS.DocumentEngine.RelationshipInfoProvider.GetRelationshipInfo(int,int,int) but was unable to make it work. I was able to get all the required int's, left and right document id's and the relationship id, but I don't think that function can be used inline? Do you know a way that I can return true if a relationship exists? Do I need to create a custom transformation function in the appcode to do something like this? Thank you.

Recent Answers

Joshua Adams answered on December 14, 2015 22:16 (last edited on December 14, 2015 22:19)

You could to it by creating a custom macro, which I would recommend if you need to use it in more than on place. Also, its easier to maintain and upgrade, because there is a central location to go to(App_Code). A quick approach other than that, would be to use the script runat="server" tag and to place a method inside of that. Then call the method directly in your transformation. I would strongly suggest creating a custom macro method, but those are two approaches that you could take.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 14, 2015 22:23 (last edited on December 14, 2015 22:24)

In your transformation add another repeater and set it up like so:

<script runat="server">
  protected override void OnInit(EventArgs e)
      Guid nodeGuid = ValidationHelper.GetGuid(Eval("NodeGuid"), Guid.Empty);
      repRelated.Path = "/Locations/%";
      repRelated.RelationshipWithNodeGuid = nodeGuid;

<!--  your other transformation code -->

<cms:CMSRepeater ID="repRelated" runat="server" DelayedLoading="true" RelationshipName="isrelatedto" RelatedNodeIsOnTheLeftSide="true" ClassNames="MyPageType.Location" TransformationName="MyPageType.Location.LocationListLink" />

This will display related pages if there are any to this page (node guid). No need to write a lot of custom code for this.

1 votesVote for this answer Mark as a Correct answer

kyle shapiro answered on December 18, 2015 20:30

Brenden, I understand your answer, and it worked for me in the case of displaying something when the iterated item is in that relationship, but what I actually need to do is NOT show something when that relationship exists. Or show something (it's a button in html) when the iterated page is NOT in that relationship. I know I could take your solution, create a hidden element with it, and then place some javascript that would strip out the button that I don't want to show in the case of this event based on that hidden element, but I doubt that's the right way to approach this. Do you have a similar solution where the logic only shows a button if the page is NOT in the specified relationship? Thank you

0 votesVote for this answer Mark as a Correct answer

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