The final HTML rendered by the browser has links to images, other internal/external pages , besides other functionalities in the standard HTML format such as anchor tags used to represent links. However, The Links ( links to Pages, MultimediaItems, Components ) created within Tridion Content Manager are in there own language which must be processed and transformed to standard HTML tags.
Within a normal DWT, for example, we create a link to another Page simply by inserting the corresponding component used in destination page into some ComponentLink field, similar to something below:
<a tridion:href="@@Component.Fields.ProductLink@@" class="productSection" target="_blank" title="@@Component.Fields.ProductLinkText@@"> @@Component.Fields.ProductLinkText@@ </a> code sample-1
Same way we can also create a link to a multimedia component by setting the tridion:href attribute appropriately.
Ever wondered how such attributes like: tridion:href is resolved to point to the correct Page/Multimedia item present on the presentation server. How is the attribute tridion:href being used and transformed/changed to point to a valid Page URL?.
So, what happens when the above DWT code is finally processed ? Is the processing different while previewing the Page in CMS and when the Page is published ?
And one last question, How does the above DWT code gets transformed to a valid HTML displayed finally in a browser ?
Understanding What is Dynamic Link Resolving:
The Content Manager allows you to create links, that is, references from one Content Manager item to another Content Manager item.Dynamic Link Resolver can only resolve links between Content Manager items. Links to external resources cannot be resolved.
Links between different Pages. Usually Page links are created within Page Templates to create navigation structures.
Binary links point to binary files such as images, PDF documents. In the Content Manager, these binary files are represented as Multimedia Components. These links are often created in Components as Multimedia Component link fields, or in format areas(RTF) as Multimedia Component links.
Links to any Component. These links are created in a Component in various ways: as Component link fields; as Component links in format areas(RTF) etc…
Dynamic Link Resolver resolve these links in several ways:
- It resolves Component links by linking to a published Web page that contains the target Component.
- If multiple published Web pages contain the target Component, Dynamic Link Resolver identifies the best target by looking at the priority settings of Component Templates, and then at the directory hierarchy of the published site, also called Proximity.
- It ensures that links are valid when the target item is renamed or moved to a different location on the Web site.
- It manages dead links ( Pages NOT published ) by letting you choose to display the link text of the dead link, or just omit the link text.
With this knowledge on Dynamic Link Resolving and types of Links, read on to understand how the DWT code(code sample-1 above) is transformed to intermediary TCDL tags and then finally to a valid HTML displayed in browser.
Publishing a Page:
When a page is published, it helps to break the processing in 3 stages.
Stage I: Processing by the Link Resolver Template
The Link Resolver TBB rewrites these links to Components in the Tridion Content Delivery Language (TCDL) format.
Thus, the above code sample-1 when rewritten in TCDL format by the Link Resolver TBB will look like:
<tcdl:Link type="Component" origin="tcm:123-250233-64" destination="tcm:123-654674" templateURI="tcm:0-0-0" linkAttributes=" class="productSection" title="Product" " textOnFail="true" addAnchor="false" variantId="">Product</tcdl:Link>
Stage II: Processing by the Deployer
And , Finally when the above TCDL tag is processed by the deployer, the final Asp.Net code generated will be :
<tridion:ComponentLink runat="server" pageURI="tcm:123-250233-64" componentURI="tcm:123-654674" templateURI="tcm:0-0-0" addAnchor="false" linkText="Product" linkAttributes=" class="productSection" title="Product" " textOnFail="true"></tridion:ComponentLink>
- The above final Asp.Net code can be seen in the Page deployed/present on the CDA server , in the Website’s appropriate folder. Open the page in Notepad to view such tags.
- Deployer will create these Custom Control tags (Asp.Net based Controls ), if the below settings are present in the cd_deployer_conf.xml file.
<Property Name=”tcdl.dotnet.style” Value=”controls“/>
<Property Name=”tcdl.jsp.style” Value=”tags” />
- In case, settings as in point 2 above is NOT present, then deployer will generate Inline Code to render the standard HTML corresponding to the TCDL tags. NO Asp.Net Custom Web Server Control will be generated. See an example below for Inline Code.
The tridion:href attribute ( used in DWT Code) value is placed into the ComponentURI attribute on transforming into TCDL format. The other attributes like: class,title are placed into the LinkAttributes atribute. A separate blog post of mine will cover these in full details.
Stage III: Runtime Processing
This is where the Dynamic Link Resolver plays its role. The Asp.net based server control tags are resolved at runtime – on server side – when a user requests the Page.
- The Dynamic Link Resolver processes these custom control tags thus converting them to the Standard HTML anchor tags.
<a target="_blank" href="http://www.testWebsite/product.aspx"> ProductSection </a>
- Additionally the Dynamic Link Resolver makes use of the configuration settings from file: cd_link_conf.xml , if required .
- In case resolving fails for some reasons, then either no link is generated, or plain text without a hyperlink is displayed, based on value of attribute: TextOnFail
- The dynamic Link resolving functionality is provided by the classes present in cd_Linking.jar package. This jar package is present inside the ‘lib’ folder inside ‘bin’ folder of the website.
Inline Code Sample:
You can also write some Inline code directly in your Template (DWT), or, write this inline code directly in an aspx page present on a server to create a Link:
<%@ Import namespace="Tridion.ContentDelivery.Web.Linking"%> <% ComponentLink componentLink = new ComponentLink(); %> <!-- A sample component link --> <% Response.Write(componentLink.GetLinkAsString("tcm:123-250233-64", "tcm:123-654674", "tcm:0-0-0", "class=\"productSection\"", "SampleLink",true,false));%> <!-- end of component link --> <% componentLink.Dispose(); %>
- The above code sample creates a link to a destination page containing the Component with URI: tcm:123-654674
- There are other versions of GetLinkAsString() method to create links to Binaries, Pages to Pages.
- Such Inline codes are generated by Deployer as an alternative to Custom Web Server Controls.
Previewing a Page :
However, when a Page is previewed in CMS, such as when you select a page and click the Preview button, then in this case Dynamic Link Resolver plays NO role and the Link Resolver TBB detects the Preview mode and will render/rewrite these links in its Preview Skeleton defined as:
Where CME_PREVIEW_URL will be the Preview URL of your Tridion installation and will be something similar to: /WebUI/Editors/CME/Views/Popups/Preview/Preview.aspx
As a last note, make sure below web.config settings are in place for such TCDL tags to be rendered correctly:
<pages> <controls> <add tagPrefix="tridion" namespace="Tridion.ContentDelivery.Web.UI" assembly="Tridion.ContentDelivery" /> </controls> </pages>
Hope you enjoyed this post. Comments and Suggestions are welcome.