Syntax proposal for HTML attributes

2001-12-08
2001-12-13
  • Kurt Stephens

    Kurt Stephens - 2001-12-08

    Like others in this group, I have some philosophical qualms regarding the invalid HTML sytnax produced using TMPL_VAR in HTML attributes, i.e:

    <img src="<TMPL_ATTRIBUTE NAME=param>">

    Coming from an intense infatuation with Zope PageTemplates and the associated Template Attribute Language, I propose adding a TMPL_ATTR expression that would serve as an alias for TMPL_VAR in HTML attributes.  The syntax would be as follows:

    <img TMPL_ATTR="ATTRIBUTE=src NAME=img_url">

    The 'ATTRIBUTE=' would be optional, all other parameters would be identical to those used by TMPL_VAR.  The TMPL_ATTR expression would be processed in HTML::Template::_parse after the Vanguard compatability mode hack using a regex that converts this into the standard TMPL_VAR syntax.  I have written such a regex that yields the following results:

    Before:
    <img tmpl_attr="attribute=src escape=url name=img_url"
    tmpl_attr="width name=img_width"
    tmpl_attr="attribute=height img_height">

    After:
    <img src="<TMPL_VAR escape=url name=img_url>"
    width="<TMPL_VAR name=img_width>"
    height="<TMPL_VAR img_height>">

    (Pardon any line wrapping)

    I am currently testing a patch that implements this functionality.  The patch includes a 'new_style_attributes' parameter for HTML::Template->new that optionally enables TMPL_ATTR processing.

    Comments, anyone?

     
    • Kurt Stephens

      Kurt Stephens - 2001-12-08

      Oops, I meant

      <img src="<TMPL_VAR NAME=param>">

      in the OP, line 4.

       
    • Andrey Melnikov

      Andrey Melnikov - 2001-12-09

      Sounds good, but I think HTML::Templates has several disadvantages if compared with other template libraries, not one. Maybe it's time to write it again from scratch, saving old syntax as-is where possible?
      For example I think we should separate template parsing from modperl-specific code.

       
      • Jeff Dafoe

        Jeff Dafoe - 2001-12-09

             Why reinvent the wheel?  Use something like Template Toolkit if you need more capabilities than what HTML::Template offers.

         
        • Andrey Melnikov

          Andrey Melnikov - 2001-12-10

          There are too many template libraries in the NET and it's impossible to find the right one :((((

           
          • Jeff Dafoe

            Jeff Dafoe - 2001-12-12

                 Template Toolkit is the right one.  www.template-toolkit.org . 

            Jeff

             
            • Sam Tregar

              Sam Tregar - 2001-12-12

              "HTML::Template, wassssssssup?"

              "HTML::Template - you've got the right one, baby."

              "HTML::Template - it's what's for dinner."

              Maybe I should hire an advertising firm?  Or maybe you should take your advertising someplace more appropriate?

              -sam

               
              • Jeff Dafoe

                Jeff Dafoe - 2001-12-13

                     I only mentioned it when the suggestion to rewrite HTML::Template from scratch arose.  Such development energies would be better focused on adding features such as shared-memory template caching to TT, which has kind of become the de-facto templating library for perl.  This doesn't mean that there isn't a place for lightweight libraries such as HTML::Template just that future substantial development energies would be more beneficial to the perl community if directed to the appropriate resource. 

                Jeff

                 
      • Sam Tregar

        Sam Tregar - 2001-12-09

        What mod_perl specific code are you talking about?  Caching isn't mod_perl specific at all - it just happens to be a popular use case.  Both the file cache and the shared memory cache work with normal CGI.

        -sam

         
        • Andrey Melnikov

          Andrey Melnikov - 2001-12-10

          Really? How can I enable template caching under normal CGI? Does caching help a lot?

           
          • Sam Tregar

            Sam Tregar - 2001-12-12

            my $template = HTML::Template->new(filename => 'foo.tmpl', file_cache => 1, file_cache_dir => '/tmp');

            Both file_cache and shared_cache work with normal CGI.  Read the documentation for more details!

            -sam

             
    • Sam Tregar

      Sam Tregar - 2001-12-09

      Sounds like a good idea for a filter!  I doubt I'd put it in the main module but I'd be happy to see it as an add-on module ala HTML::Template::Expr.

      Why don't you join the mailing-list and post about it there?  We've been discussing how to make combining add-on modules easier.

      -sam

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks