Kentico 8.2 k# Macro Optimization Question

Jared Gotte asked on June 9, 2015 23:05

All 4 of the following k# macros return the same thing:

  1. {% DocumentName %}
  2. {% CurrentPageInfo.DocumentName #%}
  3. {% CurrentDocument %}
  4. {% CurrentDocument.DocumentName #%}

Please tell me which one is optimal and why. Thanks!

Correct Answer

Jared Gotte answered on June 18, 2015 20:08

I got the answer after submitting a support ticket.

Depending on the context, {% DocumentName %} and {% CurrentDocument %} both get resolved to {% CurrentDocument.DocumentName |(identity)GlobalAdministrator%} is the most optimal out of these 3 choices.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Dawid Jachnik answered on June 10, 2015 08:11 (last edited on December 10, 2019 02:30)

Hello Jared,

{% CurrentDocument.DocumentName |(identity)GlobalAdministrator%}

I think that this macro is the most optimized, because you relay the context "CurrentDocument" of the data you want to read "DocumentName".

3 votesVote for this answer Mark as a Correct answer

Martin Danko answered on June 10, 2015 08:30

Hello Jared,

regrettably Dawid is not right in this case.

You should use CurrentPageInfo instead of CurrentDocument, since you're accessing information that is available from CMS_Document table, and values from this table are accessible through PageInfo. PageInfo is cached, and already available because Kentico URL Rewriting engine retrieved it at the beginning when getting base info about requested page. Unlike PageInfo, CurrentDocument will execute extra SQL query to get pretty much same data (+ coupled table data of course).

I would recommend you to watch also this great video recorded by Miro Remias - our Sr.Solution Architect:

you can also download the PowerPoint presentation when exactly this is explained on the slide no. 8.

Best regards, Martin

3 votesVote for this answer Mark as a Correct answer

Jared Gotte answered on June 10, 2015 20:59 (last edited on December 10, 2019 02:30)

Thank you, Dawid and Martin. I came across this Kentico 7 documentation saying that CurrentPageInfo is more optimal than CurrentDocument when Content caching is enabled (which it is in our environment). However, that knowledge seems to be lost in the Kentico 8 documentation. I didn't provide it in the question because I wanted to see if anything has changed. So I'm convinced now that using CurrentPageInfo is better than CurrentDocument in this case. But why is {% CurrentPageInfo.DocumentName |(identity)GlobalAdministrator%} if that is the case? Please clarify. Thanks!

EDIT: This is my first time submitting a question through the Questions & Answers service so I apologize if I'm using it inappropriately. I don't know how to properly ask for clarification to an answer without submitting another answer or editing my original question. If I were to edit my question.. then it's not fair to the people who answered the original question.

1 votesVote for this answer Mark as a Correct answer

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