How do I get the name of document by its node ID in a macro?

Bryan Drenner asked on February 20, 2014 13:11

How do I get the name of a document by its node ID in a macro?

I wish there was something like {% Documents.GetById(4).DocumentName %}.

Correct Answer

Pavel Janečka answered on February 21, 2014 04:14

Hi, actually, the semantics of the macro is: {%Documents[index]|(identity)GlobalAdministrator%}

You can also get your Document by node alias path by using Documents["NodeAliasPath"].DocumentName

2 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on February 20, 2014 14:29

Your wish has been granted! You should be able to use:

{% Documents[nodeId].DocumentName @%}

2 votesVote for this answer Mark as a Correct answer

Bryan Drenner answered on February 20, 2014 14:43

@BRENDEN KEHREN: Thanks for your help. I'm getting a strange result from using a node ID like that. When playing with a default install of the Corporate Site template, the "/Services/Web Design" document shows "Node ID: 28" under its Properties tab. However, if I use {% Documents[28].DocumentName @%}, the rendered name belongs to a different document altogether. Any thoughts?

0 votesVote for this answer Mark as a Correct answer

Pavel Janečka answered on February 21, 2014 04:16

And I see I forgot the '@' sign at the end of the macros, sorry for that!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 21, 2014 06:30

@Bryan, I did my testing and it worked as expected although I was fortunate enough my index and node id were the same for the 3 documents I tried. Pavel is correct, I'd use the WHERE clause to get what you're looking for.

0 votesVote for this answer Mark as a Correct answer

Bryan Drenner answered on February 21, 2014 09:59

@PAVEL JANECKA: To be sure, wouldn't the node ID always be unique?

0 votesVote for this answer Mark as a Correct answer

Pavel Janečka answered on February 22, 2014 03:46

@BRYAN DRENNER: yes, it would.

0 votesVote for this answer Mark as a Correct answer

Saurav Kumar answered on March 3, 2017 09:00

Hi All,

How can I access Documents using its nodealias property in the where clause but from a different website on the same instance of Kentico. Something like below but with a site identifier or something.

Documents.WithAllData.Where("NodeAlias = 'acai-rice-pudding-bowl'").FirstItem

Regards, Saurav

0 votesVote for this answer Mark as a Correct answer

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