Resolving Parts of Current Path in API

Tobias Beckendorff asked on November 2, 2017 14:37

Hello,

In our projects we use a lot of relative path expressions for DataSources, Repeater, ect. like /{0}/{1}/%.

Is it possible to resolve such an expression in the code behind of a custom WebPart through Kentico API?

Thanks a lot in advance, Tobi

Correct Answer

David te Kloese answered on November 3, 2017 09:27

Nice question... took me a bit trial and error but got it to work.

You'll need to resolve the macro from code... which can be done using the MacroResolver.Resolve().

But since you're using a relative Path you'll need a macro to resolve the path macro... you still folowing? ^_^

To resolve page path expressions, use the following standard macro: {% Path["path"] |(identity)GlobalAdministrator%}")

Note that if you don't use the escaped double quote it doesn't work.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Joel Macaluso answered on November 2, 2017 20:28

Hi Tobi - not sure exactly what you need, but a good place to start would be the DocumentEngine namespace. With that you could get the parent / folder of a the current page and then perform the operations you need, for example (things like CurrentDocument.Parent.DocumentNamePath).

This page explains the possibilities pretty well - https://docs.kentico.com/k10/custom-development/working-with-pages-in-the-api. You probably already checked there so if you have a specific example of what you'd want to do in the custom web part I'm sure someone can provide more info.

Joel

0 votesVote for this answer Mark as a Correct answer

Tobias Beckendorff answered on November 3, 2017 09:50

Hi David,

thank you, this is exactly what I was looking for and it works!

I would have never guessed to look for the solution at the macro level.

Tobi

0 votesVote for this answer Mark as a Correct answer

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