A document model |
[eluser]wr5aw[/eluser]
Some time ago, I created some methods to manipulate and render various pieces of an html document. It's evolved into a pseudo document model. I've been using it in some CI projects and it really comes in handy. The model is a collection of properties and containers with methods to render tags or groups of tags. I also wanted to be able to append or prepend items so they could be rendered in a specific order. Here an example of working with the page title: Code: $this->document->title = 'My Site'; Here's an example of rendering the DTD: Code: // in a controller or anywhere else How about rendering a complete html opening tag: Code: echo $this->document->render('htmlopen'); Let's add some stylesheets: Code: $this->document->addStylesheet('/path/to/css/print.css', 'print'); There are seven core containers - title, metas, stylesheets, css blocks, scripts, script blocks, and bottom script blocks (really just another script blocks container). All of the containers can be appended or prepended and have render methods. Then there are a number of properties including doctype, character set, language, language direction, meta description, meta keyword, etc. Doctype, character set, meta description and meta keywords all have render methods. Finally, there's the ultimate lazy view: Code: echo $this->document->render('doctype'); I was thinking about posting it on github. If you're interested, post back and I'll go ahead and put it in the wild.
[eluser]wr5aw[/eluser]
Pushed to github - https://github.com/alwarren/codeigniter-document_model Still haven't added the renderHead() method that I cited in the last example. Should only take a few minutes but I'm feeling a little lazy. No docs either. The original post should be self-explanatory. |
Welcome Guest, Not a member yet? Register Sign In |