Find page type in folder

Alex Koshel asked on December 23, 2021 20:34

Image Text Hi. I have a folder structure like this. How to get url page type A in page type B?

Correct Answer

Juraj Ondrus answered on December 25, 2021 07:15

You can do it as David suggested. I would maybe add .TopN(1) parametrization or, you could just select page in given NodeAliasPath or, with given NodeParentNodeID and use the .ClassName("className") parameter. Please see the API examples

If you want to use macros, here are some samples to give you some ideas, but keep on mind the performance!

  1. If the page of type A will be always the first child: {% Documents["/folder"].Children.FirstItem.AbsoluteURL %}
  2. In case there are more pages of the same type, use the FirstItem for example or, you will need to specify which item to select: {% Documents["/folder"].Children.ClassNames("page.type.A").WithAllData.FirstItem.AbsoluteURL %}
  3. And if you want go fancy, you could use something like this: {%Documents .Columns("<set the page type A fields you want to use separated by comma>") .ClassNames("page.type.A") .WithAllData .Where("NodeAliasPath LIKE '/folder/%'") .OrderBy("NodeID DESC") .ApplyTransformation("transformation.code.name"); |(recursive)true#%}
    The Columns should list the columns from the page you want to display in the transformation - it is similar to e.g. repeater web part Columns property. I would recommend using at least these ones as some of the transformation methods need them: NodeAliasPath, DocumentURLPath, NodeAlias. And the transformation could be just standard ASCX or txt transformation as you would use with a repeater.

You can also replace the /folder node alias path with a macro if you want to have it dynamic too. But it adds more complexity and I just wanted to list some macro examples.

1 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on December 23, 2021 23:45

Hi,

just a random occurrence of page type A? Or is there always one.

I think the easiest would be to select the node of type "PageTypeA" that has the same "ParentNodeID" as the current page. This would select siblings of the other type.

Where are you needing this? In code, Control, Transformation, ...?

0 votesVote for this answer Mark as a Correct answer

Alex Koshel answered on December 24, 2021 07:49

Hi. "just a random occurrence of page type A? Or is there always one." - always one. In the template page type B. I want to create a static html webpart. And link to url page type A

0 votesVote for this answer Mark as a Correct answer

Alex Koshel answered on December 27, 2021 18:30

Replacing / folder with a macro is a great idea. have any suggestions how?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 29, 2021 05:07

Well, this depends on your structure and how the editors will work - you can use e.g. the CurrentDocument.Parent macro or, the Documents[] statement and define the NodeAliasPath dynamically, etc.

1 votesVote for this answer Mark as a Correct answer

Alex Koshel answered on December 29, 2021 17:51

Thank you very much

0 votesVote for this answer Mark as a Correct answer

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