4 ms·
> using functions as tag libraries. Care to post an example ?
by guggle 7y ago
> using functions as tag libraries.
Care to post an example ?
- pjmlp 7y agoBasically you split the PHP code into three layers, trying to do a kind of bare bones MVC. You have the PHP business logic code as usual. Then instead of doing <a href="http://somewhere">A link</a> You have a view function that does that for you function web_link($url, $title) { echo "<a href="$url">$title</a>"; } And then on the HTML markup, you place those calls as tag libraries in other similar frameworks, web_link("http://somewhere", "A link") Very low tech, but does the job similar to JSP tag libraries and provides some organization.
- guggle 7y agoLow-tech is fine, however I'll assume your example has been excessively simplified for the sake of brievity because as-is it's prone to break your page.
- pjmlp 7y agoYes, I was making it basic, just describe the idea behind it.
- deleted 7y ago[deleted]
- stef25 7y agohttps://codeigniter.com/user_guide/helpers/html_helper.html https://codeigniter.com/user_guide/helpers/html_helper.html
- pjmlp 7y agoYes that is the idea, it just did not exist in 2003.
- krapp 7y agoIt seems too low tech to be useful for any project of any complexity. Existing HTML template frameworks do a lot of things like character and syntax aware data escaping (and avoiding double-escaping), template caching, plugins, code generation, tag extension, filters, etc. Other than being slightly more concise and appearing more functional, I don't see the benefit of this over something like Twig or Smarty. At some point you're going to wind up re implementing features that already exist in a framework anyway.
- pjmlp 7y agoNaturally if one is doing it at scale, this is NIH. I used it only for my web site, and many alternatives did not exist back when I did this.