4

Is there any way to get page url based on component Id and template priority. I am using the following code to get the page url but this doesnot consider the template priority and return the first page found.

 var componentLink = new ComponentLink(componentTcmUri.PublicationId);
 var link = componentLink.GetLink(componentTcmUri.ItemId);
 var url = link.Url;
4

You are correct, the GetLink(Int32) and GetLink(String) methods of the ComponentLink class ignore template priorities. This is stated in the documentation (CHM file).

You need to use a different overload - either of:

  • GetLink(Int32, Int32, Int32, String, String, Boolean, Boolean)
  • GetLink(String, String, String, String, String, Boolean, Boolean)

will consider template priorities.

If you do not have a Page URI (or a Template URI), you can use a null URI, like:

Tridion.ContentDelivery.Web.Linking.Link link = cl.GetLink("tcm:0-0-0", "tcm:69-1345", 
                                                           "tcm:0-0-0", "", 
                                                           "text", true, true);
| improve this answer | |
  • Thanks David, As per documentation the component link picks up the link with highest priority. The other overloaded method requires page id as well which i don't have. – rdhaundiyal Apr 15 '13 at 11:11
  • 4
    You can use "tcm:0-0-0" instead. Ideally though, do specify a valid page URI so that the link can be cached. This is the URI of the current page, not the target, and if you don't care about proximity rules, use your home page URI. – Nuno Linhares Apr 15 '13 at 11:29
  • 1
    I'm not sure if we mean the same thing here. The documentation for the GetLink methods with only an ID as a parameter state: Gets a URL to the first page that is found containing the requested targetComponentId. Template priorities are ignored for this specific method. – David Forster Apr 15 '13 at 11:30
  • ... And I was just about to write, you can use a Null uri of "tcm:0-0-0", but Nuno beat me to it :) I will add the info to my answer – David Forster Apr 15 '13 at 11:30
  • 2
    Templating priority is automatic through the component linking API. You don't specify the priority you want to look for - The API finds the page where the component is used with the highest priority component template it can find, excluding the template that you (may) specify. In the case of multiple uses of the same highest priority there is an algorithm that determines the most appropriate of those to link to – David Forster Apr 15 '13 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.