Friday, December 06, 2013

Tapestry Quicky: ConditionalComment

Here's a quicky I just put together for a client to generate IE conditional comments. This isn't a feature supported by Tapestry's JavaScriptSupport (for libraries; it is support for CSS files).

Fortunately, this is something that comes together in Tapestry in almost no code:

This is what it looks like in a template:

And here's the markup it produces:

And that's the whole point ... the URLs for the referenced JavaScript libraries are now Tapestry assets, and will have access to Tapestry's asset pipeline as unique resources, including GZip compression and minimization.

It is always important to me that Tapestry not get in the way: frameworks that lock you down and prevent you from accomplishing your goals should not be used. Tapestry has a long history, and there are certainly many areas that could have been implemented differently, or simply not implemented at all, but it's nice that most edge cases, like this one, have a simple solution.

3 comments:

  1. Hello,

    I have a problem with your conditionnal comment...
    It comments also all my javascript !

    ReplyDelete
  2. Hello,

    I am trying to do the same but with the html tag. Enclosing html tags within multiple conditional comments.

    This is the html conditional comment css trick:
    https://github.com/h5bp/html5-boilerplate/blob/v4/index.html

    It helps you have css classes set to the html tag that helps you identify which browser is accessing the page.

    eg:


    I am just trying to figure out where I have to hook in the services to transform the html tag into this conditional comment soup :)
    Any advice ?

    Best regards,

    Numa

    ReplyDelete
  3. Hi,

    Sorry for my previous comment, I found a solution :) I was looking for a complex solution and did not even tried the obvious one....
    I just tried pasting the html header with conditional comments as is in the tapestry Layout component. And tadadam!!! It works straight out of the box.
    I just hope that when I go to production it doesn't strip these comments :)

    Numa

    ReplyDelete

Please note that this is not a support forum for Tapestry. Requests for help will be deleted. Please subscribe to the Tapestry user mailing list if you are in need of support, or contact me directly for professional (for pay) support.

Spammers: Don't bother. I delete your comments and it's a waste of time for both of us. 垃圾邮件发送者:不要打扰。我删除您的评论和它的时间对我们双方的浪费