1

I have a Component that contains a field as Component Link. I would like to assign a hyperlink to that Component. What is the equivalent of <a tridion:href="TCMID">text</a> for a Razor Template?

My Previous code is:

 <a [email protected]>Learn More... </a>

I got it not resolved and my html page shows as below

<tridion:componentlink textonfail="true" linkattributes="" linktext="" addanchor="false" templateuri="tcm:0-0-0" componenturi="tcm:348-13853" pageuri="tcm:348-13905-64"> 
Learn More...                                                            
</tridion:componentlink></li>

and after as per suggesstions i modified the code as below

<tcdl:Link type="Component" origin="@Page.ID"
  destination="@incomps.Fields.SecondBlockComponentLink.ID"
  templateURI="@ComponentTemplate.ID" linkAttributes="" textOnFail="True" 
   addAnchor="False">
   Learn More... 
 </tcdl:Link>

But its failed on deployment phase of publishing and the error is

Stack: TAG: (0) Param=false Mode=0
Class=com.tridion.tcdl.tags.DefaultTagHandler ------
 , Unbalanced tags in TCDL file Closing Tag 
 cdl:Link does not match tcdl:ComponentPresentation

How to resolved the below HTML output of Tridion Component Link

5
  • I suggest you take a look at the edits I made to your question which properly formats and displays code, else your question would be unreadable. Also I suggest you read through the Razor Mediator documentation since I would expect the answer to your question is in there. Mar 6, 2014 at 9:48
  • Not having used Razor ... but isn't it essentially the same, i.e. <a tridion:href="@incomps.Fields.SecondBlockComponentLink.ID">Learn more...</a> -- you're only outputting the TcmID into a link? Mar 6, 2014 at 11:15
  • I've edited your question to make the incorrectly indented code show up, but I think your question is a bit messy, perhaps it is wise if you edit it again yourself and make it more clear. Please note that any code should be indented with four spaces, for more info check out the help center Mar 19, 2014 at 8:06
  • I'm a bit lost, you mention that your <a href=@ID> did not get resolved, but you did have a <tridion:componentlink> tag in your output? That means it did get resolved correctly. The error you see when you use the TCDL tag, seems to indicate there is some incorrect HTML, that could be from a Page Template or a Component Template, you will need to debug the templates to find out where it goes wrong, or place the entire code of them in your question (try simplifying them first to reduce the amount of code and possibilities for error). But I'm certain you don't need the TCDL. Mar 19, 2014 at 11:37
  • Dear Bart, As I mentioned, When I use the <a tridion:href="Component.ID">, I got it resolved and the out put as <tridion:componentLink>. But it suppose to be the actual URL. Is there any need to add cd_tags.tld in our include library to get it resolved? Apart from everything, is giving a component link which needs to take to a page of that component is that much complicated in RAZOR? which is a basic requirement Mar 20, 2014 at 4:25

3 Answers 3

2

The syntax <a tridion:href="TCMID">text</a> has actually got nothing to do with Dreamweaver templating. The attributes such as tridion:href are actually processed by the Link Resolver template building block (usually in your Default Finish Actions).

All you have to do in Razor is take care of outputting exactly what Dreamweaver would have done, so your code would probably be something like:

<a href="dummy.html" tridion:href="@incomps.Fields.SecondBlockComponentLink.ID">Learn More... </a>
1

Abdulla,

There is no Razor way of creating component links, and there fore its not documented in there.

If you search next time you see more people looked for it;

https://tridion.stackexchange.com/a/2220/219

<a [email protected]>Learn More... </a>

If you do this before the Link resolver TBB (normally in the Default Finish Actions), then the TCDL and eventually the dynamic link control, will also be generated for you.

1

There are two ways to handle this (probabaly more, but lets discuss the simple ones).

  1. Use the Default Finish Actions TBB
  2. Output the TCDL code yourself (no TBB needed)

Both of these cases require you to have setup a correct Deployer, which will transform the TCDL into the correct output on the delivery side.

#1

In this case, you are using the Default Finish Actions to handle your links, the documentation describes you will need to supply a tridion:href attribute in your link and place a TCMURI inside of it, so try the following in your Razor template:

<a tridion:href="@incomps.Fields.SecondBlockComponentLink.ID">Learn More...</a>

#2

In this case you ignore the default TBBs and their handling, so you will just manually output the correct TCDL for the Deployer to handle. So the following will just go in your Razor template:

<tcdl:Link type="Component" origin="@Page.ID" 
           destination="@incomps.Fields.SecondBlockComponentLink.ID" 
           templateURI="@ComponentTemplate.ID" 
           linkAttributes="" textOnFail="True" addAnchor="False">
    Learn More...                                                         
</tcdl:Link>

Now all of this is just based on common sense, the documentation and trying the same as I would do in a DWT Template. I have never used the Razor mediator, so your mileage may vary.

I would suggest you use #1, since I have a feeling #2 will have an issue resolving @Page.ID, although I believe you could set that to tcm:0-0-0 too.

In short to answer your question:

What is the equivalent of <a tridion:href="TCMID">text</a> for a Razor Template?

Well it is exactly that, use the exact same code and make sure you use the Default Finish Actions TBB.

2
  • Dear Bart, I used the Default finish actions tbb. and i got the below error message at that time of publishing deployment. Stack: TAG: (0) Param=false Mode=0 Class=com.tridion.tcdl.tags.DefaultTagHandler ------ , Unbalanced tags in TCDL file Closing Tag tcdl:Link does not match tcdl:ComponentPresentation Mar 19, 2014 at 9:51
  • @AbdullaKalifullah maybe you should edit your question and provide that information in there, since without information like that nobody can fully answer your question. Mar 19, 2014 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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