I'm moving a tridion site from asp.net to java and I am wondering about how to handle the taglib declaration for tridion tags (ComponentLink, ComponentPresentation, etc.) at the top of the page. It seems from my research that it's generally put in the page or component template. This seems odd to me. I thought one of the benefits of tcdl tags being converted to a specific language during deployment was to keep the Content Management environment language agnostic. If I have to hard code the taglib declaration into the template I am no longer language agnostic... Granted you have to specify the page extension (jsp, aspx) in the CMS but it still seems counter intuitive. Is there an out of the box option for this that I'm missing or would I need to consider a deployer extension to inject the declarations in the page during deployment?
As far as I have seen, most people place the snippet at the top of the Page Layouts. I understand the point you are making by not embedding the taglib - but out of the box this functionality doesn't exist. I would actually suggest writing a 'language agnostic' TBB that either checks the extension of the page being published, or the output type of the publication target and based on that injects the respective string.
So the TBB would run (after the DWT) and see that our page is a jsp page (as an example), and then find the head of the document through a regular expression and inject the following.
Update: A way to write the TBB being consistent with the OOTB TBBs (such as the Link Resolver) would be to define a custom TCDL tag, such as:
and use a regular expression to parse your page's output for your custom tag, and have it swap the tag with the appropriate string. It would give you a bit more control around placement of the tag.
The likelihood of there being much benefit to be had from language-agnostic templates is almost certainly small. Most people would be OK with accepting some amount of language-specific things in their templates. So even if you can manage to achieve this technically (I'm sure you can.), it's probably still more effort than dropping these declarations into the page template, and fixing it up again on some putative future occasion when you change technologies again. Even then - when you change technologies again - you'll almost certainly change some other aspects of your design, so you'll be updating your code anyway, and you'll have a project with a budget.