how can i access the nodealias of parent document in my url pattern of page type?

Muhammad Kaleem asked on April 17, 2019 17:13

i'm using kentico12 mvc and i have created four page types 1)destinations 2)regions 3)country 4)city

in the url pattern of page type i give url pattern to page types as

page type: destinations, url pattern: /destinations page type: region, url pattern: /destinations/{%NodeAlias%} page type: country, url pattern: /destinations/{%Documents[NodeAliasPath].Parent.AliasPath#%}/{%NodeAlias%}

here i'm facing problem how can i access the nodeAlias of region, to access the nodealias of regions i give "{%Documents[NodeAliasPath].Parent.AliasPath#%}" in url pattern of country but unable to access the region

please help if anyone knows about this, any help will be highly appreciated

thanks...

Correct Answer

Trevor Fayas answered on April 17, 2019 20:44

For the mvc route, you can do /destinations/{parent}/{nodealias}

As for the presentation url on the page type... You may need to implement a custom macro method that will return the parent node alias, I'm not 100% positive if it will trigger in the rendering of the url, I'll check it out! Give a little

1 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on April 17, 2019 18:02

I believe the url patterns must be based on the current document. I'm confused why you would have one page type have the same url of another.

You may just need to give it it's own pattern not based on its parent and set up a redirect or use a custom route handler. Can you explain more your reasoning behind the logic?

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on April 17, 2019 19:56 (last edited on April 17, 2019 19:57)

thanks trevor, all the page types i'm using are different i want to access the document page of country by its name i.e.

destinations/europe/germany

destinations/asia/uae

user can add multiple continents under the destinations document like europe, asia and so on... under one continent user can add multiple countries like

destinations/asia/india

destinations/asia/uae

here i'm facing problem unable to access third node of countries, please can you help how can i access country?

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on April 17, 2019 20:47

thanks trevor fayas, its working fine...

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on April 17, 2019 21:41

I did confirm that custom macros DO run in the presentation url, so absolute worse comes to worse, you could write a custom macro that generates the proper path for the presentation URL.

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on June 6, 2019 21:13

Hi Trevor, can you please explain about implementation of custom macro method that will return the parent node alias in url pattern of page type?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 6, 2019 21:18

You can create a custom macro method here:

https://docs.kentico.com/k12/macro-expressions/extending-the-macro-engine/registering-custom-macro-methods

Then for the Page Type Url Pattern, you can do {% MyCustomMacro(NodeAliasPath) %}

where MyCustomMacro would return the proper path.

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on June 6, 2019 21:47 (last edited on December 10, 2019 02:31)

I give url pattern for country like this

/{%DocumentCulture%}/destinations/{%Parent%}/{%NodeAlias%}

and for city like this

/{%DocumentCulture%}/destinations/{%Parent.Parent|(identity)GlobalAdministrator%}

thanks

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 6, 2019 22:37 (last edited on December 10, 2019 02:31)

Make a custom macro method in the Util Namespace that is "GetDestinationPath(NodeAliasPath)"

In that method, get the TreeNode of that NodeAliasPath

var ThePage = new DocumentQuery().Path(NodeAliasPath).FirstOrDefault();

Then do a switch on the class name to determine the proper path.

switch(ThePage.ClassName.ToLower()) {

case "custom.country": 
    return string.Format("/{0}/{1}", ThePage.Parent.NodeAlias,  ThePage.NodeAlias);
case "custom.city":
    return string.Format("/{0}/{1}/{2}", ThePage.Parent.Parent.NodeAlias, ThePage.Parent.NodeAlias, ThePage.NodeAlias);
}

Lastly, for your URL pattern, you would do:

/{%DocumentCulture%}/destinations/{% Util.GetDestinationPath(NodeAliasPath) |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Erick Valdivieso answered on June 7, 2019 23:05

Hi Trevor, I am interested in that GetDestinationPath custom macro you describe, could you provide the full working file for reference, I also need to be able to configure a page type to generate pages under different URL structures.

Thanks

0 votesVote for this answer Mark as a Correct answer

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