Get Document by URL in macro

Mateusz Żebrowski asked on September 24, 2015 11:49

I'd like to write macro expression that get document by url and retrive value from its property. Is it sossible?

Recent Answers


Maarten van den Hooven answered on September 24, 2015 12:03 (last edited on September 24, 2015 12:06)

Hi Mateusz,

Yes this is possible, you can use this macro {% Documents["NodeAliasPath"].DocumentName %} or if you want another (custom) property {% Documents.WithAllData[NodeAliasPath].GetValue("YourProperty") %}

Or create an custom macro, advantage of creating your own macro is that you have more control on the code and queries behind it. Because an macro with WithAllData is not efficient.

Here some documentation for creating custom Macros and using the Kentico API for getting the correct value. Registering custom macro methods Working with documents in the API

Good luck with developing!

If this answer helped you, please vote for my answer :-)

1 votesVote for this answer Mark as a Correct answer

Mateusz Żebrowski answered on September 24, 2015 13:15

Expression:

{% Documents["NodeAliasPath"].DocumentName %}

works good. But WithAllData have no effect. Is it possible to solve this using Transformation Methods?

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 24, 2015 13:32

Hi Mateusz, are you sure that you use the right field name and that this is filled?

I tested this {% Documents.WithAllData["/Home"].GetValue("NodeID") %} without any problems.

You can also have a look in the Event log if you see a error.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 25, 2015 09:06

Good morning Mateusz, If you use Kentico 8+ you can also test the macro easily in the Macro console. You can find the Macro console in "System -> Macros -> Console"

0 votesVote for this answer Mark as a Correct answer

Mateusz Żebrowski answered on September 25, 2015 10:26

Well I didn't write it but I'm using Kentico 7. Anyway I search in documentation but I can't find anything about Documents[AliasPath] or Documnets.WithAllData. Could you give me a link where i can read about it?

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 25, 2015 10:41

Hi Mateusz,

Here is an example in the documentation of Kentico 7 of the macro I described: Transformations in macro expressions

And here is an question on Devnet with a similar issue and similar answer by Jan Hermann from Kentico support : http://devnet.kentico.com/questions/getting-custom-fields-in-hierarchical-viewer-menu-transformation

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 25, 2015 19:34

Hello Mateusz, and is it working?

0 votesVote for this answer Mark as a Correct answer

Mateusz Żebrowski answered on September 26, 2015 18:10

I used other solution. Just configured another repeater. Thank for help anyway.

0 votesVote for this answer Mark as a Correct answer

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