What's the correct format for TCDL linkAttributes?

372 Views Asked by At

I can see the technology-independent Tridion Content Delivery Language (TCDL) link has the following parameters, which are pretty well described on SDL Live Content.

  • type
  • origin
  • destination
  • templateURI
  • linkAttributes
  • textOnFail
  • addAnchor
  • VariantId

How do we add multiple attribute-value pairs for the linkAttributes? Specifically, what do we use to escape the double quotes as well as separate pairs (e.g. if we need class="someclass" and onclick="someevent").

2

There are 2 best solutions below

0
On BEST ANSWER

The separate pairs are just space delimited, like a normal series of attributes. Try XML encoding the value of linkAttributes however. So, " become &quote;, etc...

If you are using some Javascript, you might take care of the Javascript quotes too, as in \".

0
On

Edit: after I figured out your real question, the answer is a lot simpler:

You should wrap the values inside your linkAttributes in single quotes. Spaces inside linkAttributes are typically handled fine; but if not, escape then with %20.

If you need something more or want something that isn't handled by the standard tcdl:ComponentLink, remember that you can always create your own TCDL tag and and use a TagHandler or TagRenderer (look them up in the docs for examples or search for Jaime's article on TagRenderer) to do precisely what you want.


My original answer was to a question you didn't ask: what is the format for TCDL tags (in general). But the explanation might still be useful to some, so remains below.

I'd suggest having a look at what format the default building blocks (e.g. the Link Resolver TBB in the Default Finish Actions) output and use that as a guide line.

This is what I could quickly get from the transport package of a published page:

<tcdl:Link type="Page" origin="tcm:5-199-64" destination="tcm:5-206-64" 
           templateURI="tcm:0-0-0" linkAttributes="" textOnFail="true" 
           addAnchor="" variantId="">Home</tcdl:Link>

<tcdl:ComponentPresentation type="Embedded" componentURI="tcm:5-69" 
                            templateURI="tcm:5-133-32">
  <span>
  ...

One of the things that I know from experience: your entire TCDL tag will have to be on a single line (I wrapped the lines above for readability only). Or at least that is the case if it is used to invoke a REL TagRenderer. Clearly the tcdl:ComponentPresentation tag above will span multiple lines, so that "single line rule" doesn't apply everywhere.

And that is probably the best advice: given the fact that TCDL tags are processed at multiple points in Tridion Publishing, Deployment and Delivery pipeline, I'd stick to the format that the default TBBs output. And from my sample that seems to be: put everything on a single line and wrap the values in (double) quotes.