How to get document by current culture in a macro using documents collection

Mark Clark asked on December 18, 2018 21:12

I am trying to retrieve a document in a macro that uses the documents collection. How do I get the desired document in the current culture if all I have is the NodeGUID?

Example: {% ApplyTransformation(Documents.Where("NodeGUID='"+SomeVariable+"'"), "SomeTransformation") #%}

Looks like Documents only references the table CMS_Document and not the view that makes the NodeGUID column available which results in an error saying NodeGUID is not an available column; however, when I try to use WithAllData I get a conversion error on the NodeGUID value as described in this article

Recent Answers

Peter Mogilnitski answered on December 18, 2018 21:51 (last edited on December 18, 2018 21:54)

you are almost there: {% Documents.Where("NodeGUID = '" + SomeVariable + "' and documentCulture='" + CurrentDocument.DocumentCulture + "'").Transform("{#DocumentID#} - {#DocumentName#}")#%} you can use Transform or ApplyTransformation(somename) (they are the same essentially).

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on December 19, 2018 03:45 (last edited on December 19, 2018 04:06)

First of all - post your comment below, please do not change the question. It would be better if you explain your scenario. May be it should be done in a different way. Where do you get this guid? {%documents. %} - gets information from view_cms_tree_joined and yes nodeguid works.

if it does not - you check in the the DB first: select * from view_cms_tree_joined where nodeguid=... this is a generic tree information. CMS_Documents has generic information about documents, cms_tree - information about parent-child tree relationship. Node does not exists in cms_document. view_cms_tree_joined does not include page type specific information, because there are different document types in your tree. I did test my answer on Kentico 11. Paste this: {% Documents.WithAllData.Where("NodeGUID = '" + CurrentDocument.NodeGUID + "' and documentCulture='" + CurrentDocument.DocumentCulture + "'").Transform("{#DocumentID#} - {#DocumentName#}")#%} see if this one works

0 votesVote for this answer Mark as a Correct answer

Harper George answered on December 24, 2018 18:38

I think you got your solution.

0 votesVote for this answer Mark as a Correct answer

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