Issue with url selctor and pages with name path urls

George Tselios asked on March 17, 2020 22:40

Dear All,

In our current project (Kentico 12SP MVC), we have setup the urls of the content pages to be constructed by the concatenation of the culture (e.g. en-us) and the name path of each node (e.g. /en-us/folder/page). So each time the name or the position of a page in the content tree is changed, the url of the page is changed accordingly.

In various page types we have fields that are links (references) to other pages of the portal (e.g. menu items). We usually implement these kind of fields using a text Data Type and Url Selector Form Control. In the settings of the Url Selector we enable the Content Tab only. So far all works well in terms of selecting a page from the content tree, but the url that is returned by the Url Selector is the relative url of the target page. The problem we are facing is that if a page is renamed or is moved to another position of the content tree then its relative url will change but the value that was selected by the Url Selector in the link field is not updated, leading to 404 errors.

We are facing the same issue with the Rich Text Editor, in cases when an author is using the "insert / edit link" tool. Similar to the previous case, the relative url of the page is stored in the resulting Html text.

As far as the link fields are concerned, we have tried to use a GUID instead of a text Data Field in order to have a "fixed" reference of the target page. The downside of this solution is that we needed an additional query (using the GUID as a selector) in order to get the actual url of the target page, so we are skeptical about proceeding this way. Also this solution does not fix the problem with the Rich Text Control.

Is there any suggested implementation or form control or configuration setting that will provide a solution to our issue?

Thanks in advance,

Correct Answer

Dmitry Bastron answered on March 19, 2020 18:09

Hi George,

Yes, unfortunately it is what it is in regards to RTE. Kentico are developing and distributing Fraola-based RTE on their marketplace, and you can ask this as question or make a feature request here I think. The more of us raise this as issue the better chance we will get it soon.

As for your questions:

  1. The menu or a footer is reasonably static global element. And you can write NavigationRepository.GetFooterLinks(..) which will return all your footer links. You can do it either one link by one or all links by IDs or any other method you like. And if you cache this - your query(es) will be performed only once. You can cache this method's result explicitly in your code or rely on CachingRepositoryDecorator from Dancing Goat example.

  2. There is no such helper directly. You need to get a TreeNode object by document GUID (check the pages API) and use .RelativeURL field of it.

  3. No, these form controls return and store GUIDs. You need to implement this logic in repository, for example. Caching strategy highly depends on the amount of data and update frequency you are operating with.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Dmitry Bastron answered on March 18, 2020 11:39

Hi George,

Regarding first point, for sure you should be using GUID of the page to store links and I don't think you should be afraid of additional query. If you choose the correct caching strategy in your code it will never be the case. For example, consider using output cache and data caching of the things returned by your repositories (have a look at Dancing Goat MVC implementation of CachingRepositoryDecorator.cs).

The second one, links in RTE. That's going to be more difficult. I'm not aware of any RTE module available that does it for you. Typically, we try to avoid using links directly in RTE and offer CTA and signpost widgets to editors and inside those widgets store page GUIDs and use those to generate links. But if you use links in RTE you would need to go back and change those links when you move the target page. Alternatively, after moving a page you can set up a 301 redirect in your configs and then you don't need to update RTE contents.

0 votesVote for this answer Mark as a Correct answer

George Tselios answered on March 18, 2020 15:17

Dear Dimitry,

As far as the RTE field is concerned, I believe that handling page references (urls) in Html text is something that all modern CMSs provide out of the box. Usually an internal identifier is stored in the Html text and each time the API requests the value of the RTE field then the identifier is automatically resolved to a friendly url.

Regarding your suggestion to use a GUID field instead of a text field for the Url Picker, I have the following questions:

  1. Let's suppose that the menu (or the footer) structure holds more than 20 url fields, do you propose that we individually cache these additional 20 queries? (Even though all we need is the relative url of the node and not any additional data)

  2. Instead of querying for the url using the GUID as parameter, is there any helper method that given a GUID returns the actual (relative) url of the page, so as to use it directly on the View?

  3. Is there any other Form Control (e.g. Page) that is suitable for page referencing which would automatically load the target node so that we do not need an additional query? In such a case how a caching strategy should be implemented?

Thanks in advance,

0 votesVote for this answer Mark as a Correct answer

George Tselios answered on March 19, 2020 16:27

Hi Dmitry,

Any suggestions?

Thanks is advance

0 votesVote for this answer Mark as a Correct answer

George Tselios answered on March 19, 2020 18:35

Dear Dmitry,

Thank you for your very helpful answers.


0 votesVote for this answer Mark as a Correct answer

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