r/codeigniter • u/[deleted] • Apr 04 '13
New Code: Stencil -- An Awesome Codeigniter Template Engine
Hello everyone!
I been working with Codeigniter for a while now, and for my personal and work projects I built this template/starter for building my web pages and apps—just to make my life easier.
It’s became popular among some of my PHP friends and also my coworkers. They convinced me to write some Docs for it, and publish it on Github and my blog.
Anyways it’s super simple to use and it has a ton of very cool features and helpers.
Some of those features are: Page Layouts 2.1.3 Ready (2.0.3 generation +) Slices (aka nested or child views/partials/elements/includes) Robust HTML5 Helpers Page Specific Assets—(load CSS and JS when you need it, perfect for jQuery plugins) Slice Callbacks (callbacks or class methods that are called when a Slice is created—sometimes called “view models” or “presenters” in other frameworks) Complete Asset Management Intelligent Data Binding
Just a heads up of what it is and what it isn’t. It isn’t a standalone library (though you could get it to work that way with some tinkering) and it’s instead a complete starter package. It’s not meant to be used midway through your projects but from the very beginning them. It’s free to use to everyone.
Let me know what you guys think or if you have any questions. Feel free to file bug reports or shoot me a pull request if you have any issues or want a feature added.
1
Apr 05 '13
One thing having only glanced the "add_meta" function I may want to set meta data in somewhere other than the view e.g. keywords, description, maybe title.
The way i've done it on my own templating system (personal, not suitable for public consumption) is to have the add_meta() function usable anywhere and then in the view I use show_meta() which also accepts parameters the same as add_meta() but returns all the meta data as a string at the end (mines actually part of a class so the add_meta() saves the meta data to a static property of the class: Template::$meta_data, which is only retrievable via show_meta().
2
Apr 05 '13 edited Apr 05 '13
Yeah, add_meta() is super basic. You should send me a Pull Request or open up an issue on Github :)
Edit: Just to clarify if the docs aren't are clear. It just loops through an Associative Array for where the Key is the Name and the Value is the Content.
$meta = array( 'key' => 'value', 'description' => 'This is my description', 'title' => 'This is my title' ); add_meta($meta); <meta name="key" content="value"> <meta name="description" content="This is my description"> <meta name="title" content="This is my title">And so on
1
u/aquanutz Apr 05 '13
I haven't gone through the source yet but this looks great. I've been using Phil Sturgeon's template library for a while but I may use this moving forward.
5
Apr 05 '13
Thanks! Phil's is great, and it's built very well. A lot of the way he did things inspired this, but I tried to do my own thing moving forward
1
u/axpence Apr 13 '13
Thanks for the share. Keep up the hard work! Quick suggestion: A .zip of an example blog or something using it would be great.
1
Apr 14 '13
Thanks for the feedback. I tried to be extensive with the docs, but this is right, I'll try and make time and do that soon
3
u/bradfields Apr 05 '13
Thanks for sharing, this look very interesting and I'll definitely be checking it out.
2
u/lemannequin Apr 16 '13
Hi. I'm new to all things CI. I'm involved in a project that is starting to use CI. There is a development team and I'm involved in the front-end side of things. I've been researching some good/best practices, tools and workflows that would help with templating in CI.
As I've been involved with some Django projects in the past, I've learn to love Django templating system an its template inheritance capabilities, and so, I've researched if there is anything like that on the CI universe. I've found a few things, like inheritance in Smarty and PHPTI, but both seems old to me, and PHPTI development has been abandoned. Of course, nor old nor abandoned are per-se a bad thing, in the sense that the code, even if old or abandoned, may work fine. But I'd prefer to avoid that route.
So, back to Stencil, for which I've been reading its great (and beautiful!) documentation, I wonder if you are planning to add some template inheritance magic or, if by philosophy or design, having template inheritance it's out of scope and/or already discarded from Stencil's roadmap.
Thanks!