5

I want to be able to use custom anchors for my Tridion project that is publishing aspx pages. So not the 1, 2, 3 etc when using tridion:anchor="true". The reason for that is that we want to use words that make sens for the visitors.

What I did so far was adding a field "Anchor" in my different schemas and write out this anchor in the different dreamweaver component templates as div with id="value of the anchor"

I created also a menu schema with for the menu items a field anchor. That way I'm already able to link to an anchor on the same page. But now we need to be able also to link to an anchor on a different page. For that I added a component link field in the menu schema. Issue is that I'm a little bit stuck with finding a way to combine the component link and the anchor.

When using page links it seems that tridion:anchor can contain a string instead of true/false. So I was thinking to try to have the same behavior for component links. In that case I see 3 places where I have to do modifications:

LinkResolver
I need to pass the value of tridion:anchor as a string instead of the expected true/false value. Or pass it as a 'new' tridion: parameter.

We have already a custom link resolver so I can do the necessary modifications here.

.net controls
On this place I need to be able to add an extra property so that I can pass the anchor as text to the ComponentLink control instead of the expected true/false value.

I found an article from Will Price about this http://www.tridiondeveloper.com/extending-linking-for-net .
Based on this article I was able to overwrite the ComponentLink control with an extra property and as an extra I modify also the urls to lowercase without default.aspx (SEO stuff)

TCDL Link Taghandler
If I see it correctly than the last thing I need to do is a modifications related to TCDL Taghandler. So that the extra parameter that I added to the ComponentLink control will be added when I publish the page or component. And on this part I'm stuck.

I found an example again from Will Price: http://www.tridiondeveloper.com/cleaning-and-extending-dynamic-linking This is using a TagRenderer and if I understand it correct than this is not rendering the ComponentLink controls but a full url. Unfortunately I didn't find anything about how to overwrite the standard behavior of the tcdl link taghandler

Is the approach I describe above a good one or are there maybe better ways to have readable and manageable anchors to components and pages?

If it's a good approach would it be possible to guide me in the good direction about what needs to be done for the TCDL part.

Thanks for the support.

2

You seem to have covered most of what's needed. The first point I'd make is that the correct approach will be very much governed by your circumstances. So for example, Will's example where he shows how to subclass a TCDL handler is more or less only justified because he's publishing REL. I don't know whether you are publishing REL. If you are, I'd suggest re-visiting Will's article, because with a little persistence, there's probably enough information there to get you where you need to be.

If you aren't constrained by needing to use REL, and assuming that it's unlikely that you'll suddenly want to switch to Java as your main platform, then you can do quite nicely without TCDL. This means simply emitting the .NET tag directly from your templating code, instead of using Link Resolver syntax.

Even if you are going to create your own TCDL handler, you may wish to emit customised TCDL from your template. Again - this is simply a case of writing out the TCDL instead of Link Resolver syntax.

This might have you wondering why anyone bothers with Link Resolver syntax at all. In fact, the Link Resolver TBB is pretty handy, as it is sensitive to whether you are previewing, in which case it emits the appropriate preview links directly. One possible approach is to have your cake and eat it - test yourself whether you are in preview mode and if so emit Link Resolver syntax. (I can't remember if there's an easy way to do that test in DWT, but you could figure it out in an assembly TBB and push a boolean to the package.)

  • I indeed skipped the TCDL part. I added directly the .net control in the Link Resolver TBB. In the TBB there is a test to see if we are in preview mode so links are also working normally in preview mode and Template Builder. So for me this was actually the solution so I will mark this. – Glenn Franquet Jan 16 '17 at 17:34
0

Updated answer to include more details

  • In DWT: add the AnchorName = "myanchor" attribute in your tag and publish your page.

  • Update the web.config of your .net project to use custom control as per link/blog below. I have not mentioned this part in blog, so please try even i am not able to recall much now. but AFAIK it should work.

  • Verify you see following Tag

Rk:ComponentLink runat="server" PageURI="tcm:85-159563-64" ComponentURI="tcm:85-159309" TemplateURI="tcm:0-0-0" AnchorName="myanchor" AddAnchor="true"

With this approach you only need to update at only once place rather than at multiple places.

PS: this approach will work with .net project only.

http://rajmittal.blogspot.in/2014/12/custom-anchor-in-tridion-component-links.html

  • Thanks Raj. That's one of the parts I had already. But the link.Anchor = AnchorName; is very interesting. I suppose that you rendered in your DWT the usercontrol itself and didn't work with <a tridion:href ? – Glenn Franquet Aug 16 '16 at 9:19
  • with link.Anchor=AnchorName it will give you the anchor name in the component. I only sub-classed the existing link, so instead of default <tridion:ComponentLink> you will get my custom<rk:ComponentLink> in your published aspx page, so everything else will work like default linking, only difference you will get your anchor in resolved URL when you access the page from Browser. also at only one place :) – Raj Kumar Aug 16 '16 at 17:51

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.