Welcome Guest, Not a member yet? Register   Sign In
Thoughts on templating
#1

(This post was last modified: 07-26-2015, 08:25 AM by ignitedcms.)

So lately I've been pondering how best to allow developers full power with ignitedCMS, my open source fully baked CMS repo.

And I'm kinda torn. I understand that you can create a page/channel (to use ee's terminology) and then dump that output from a table to view with vanilla php or codeigniter active record.

Which is great, but not very user friendly. Which is where templates come in handy. Clearly CI doesn't champion them all that much because their basic functionality is limited at best. PHP is a template language in itself, why add unnecessary bloat and limit the user to learn YAL (yet another language.)

Which is a fair point and I agree to some extent. But I can't see developers wanting to build stuff with vanilla php or CI syntax, or would they?

Or would it be a good idea to create helper functions to dump the sql, or is this just stupid because you're duplicating what a template engine already does.

What about more complicated stuff like using a session variable in a view? This is where using vanilla php with html just makes sense. Or is it worth the learning curve and extra bloat of using a proper template engine?

So is templating engines restrictive or not?
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#2

One recommendation I would have if you want to use a templating engine would be to override the Template Parser class. It's a fairly simple class, so it's usually pretty easy to integrate a templating engine as a MY_Parser class (or create a MY_Parser class that uses a driver-like system to load the configured template parser).

Personally, I prefer to use the most basic subset of PHP I can get away with in my views. If I need session data in my view, I get the data from the session in my controller and pass it to my view in a variable. I try not to use much more than variables, if/else, for/each and an occasional isset/empty/is_array. In some cases I find it easier to use a little more PHP in my view, but I usually come back to that code later and refactor it to move as much code as possible out of the view.
Reply
#3

Thanks for your input, I think I'm going to play around with CI's template parser and see if it fits my workflow. That being said php's alternate synax such as <?= $var; ?>

And for loops, looks like another way to do things like simple templates. You're absolutely right, I think view files should have for/if/else and nothing more. Any business logic that does more than this in a view probably means you need to refactor your code a lot more.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#4

(07-28-2015, 10:52 AM)iamthwee Wrote: Thanks for your input, I think I'm going to play around with CI's template parser and see if it fits my workflow. That being said php's alternate synax such as <?= $var; ?>

And for loops, looks like another way to do things like simple templates. You're absolutely right, I think view files should have for/if/else and nothing more. Any business logic that does more than this in a view probably means you need to refactor your code a lot more.

Check out my library: https://gitlab.com/david-sosa-valdes/ci-attire

Attire is an implementation of Twig template engine and Assetic asset management framework for CodeIgniter 3.0. It comes with a Bootstrap Framework template by default.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB