Custom tags

I wonder how useful it would be to have PHP parser be able to define custom tags for HTML and be able to bind various functions (or classes) to them. I’m sure somebody must be doing something like that among dozens of frameworks and template systems. However, to do it in a really nice, fast and clean way would require support from the engine parser. It might be nice as a kind of shortcut template system. It might also make much easier to use PHP with various visual design tools.

On the other hand, ColdFusion does that, and ASP does that, and not everybody likes it. But ColdFusion takes it to the extreme – language is custom tags there (I’m not a CF programmer and never played one on TV, so sorry if I just said something totally wrong and silly) , I am thinking of it just as an addition. So maybe it’s still not that stupid🙂

13 thoughts on “Custom tags

  1. Stas,

    Its easy to check the modification time of the source file and use an md5() in combination with the filename to generate the name of the ‘compiled file’

    This is how flex1.5 does things, more or less. So it would work without extra effort..

    Evert

  2. I’ve been a ColdFusion programmer for 6 years, and yah… it takes tags to the extreme. I think the tagging syntax can be a nice way of doing templates, as you say… especially if you have HTML coders doing some stuff vs. developers on it all. I’ve used ColdFusion’s JSP-style taglib support to write tags for looping and other fun stuff. Pretty nifty.

    On the topic of template languages, Django has a handy neat feature in that html files can inherit from other html files, and fill in different parts of the template.

    Does the world need another template language? I don’t know… if the templates are made by the developer, I kinda prefer the Rails approach of using the same ol’ language everywhere. That’s one less thing to learn.

  3. Well, caching is always the answer to a performance problem😉 Thus I was convinced there are frameworks that do it externally to PHP and use caching to deal with performance issues. However, I think that doing it internally would allow much easier integration with visual tools without demanding to use some specific template framework to do the parsing. Right now there’s no framework so common that a visual tool could reasonably require – thus the visual tool can’t have good “custom tag” functionality without locking user into some additional template system. Of course, you can use the tool and then generate intermediate PHP code and caching even can do this reasonably scalable – but then we have exactly the same problem which is the root of popularity for dynamic languages – once you want to change something, you’d have to go to the source template, change it and recompile it – slow process. I imagined some more “slick” solution🙂

  4. It’s not hard to do this yourself.. and you can still make it really fast by pre-generating the PHP (and make use of all the general optimization)

    It would simply introduce a compile-stage..

    If you are interested in working some stuff out, let me know

Comments are closed.