Welcome Guest, Not a member yet? Register   Sign In
Opinion: Template Engine Integration RIP?

(07-20-2016, 06:14 AM)dmyers Wrote: jlp, if we are going to be loading a "parser" as a service in CI4 using a standard class name like CI3's "parser" for that service is great but, how will multiple 3rd party developers know which parser engine is being used and how can we use multiple at the same time?

1. I use pyrocms/lex for my email template "views"
2. I use 3rd party Library "foobar" which wants me to use template library "barfoo" because it's views are in "barfoo" format
3. I use 3rd party Library "aaaa" which wants me to use template library "zzzz" because it's views are in "zzzz" format
4. I use "handlebars" for my code because of course my views are in handlebars format.

Of course in my own code I can load the template library pyrocms/lex & handlebars directly and call them as needed.
Something like this:
$this->lex_parser->parse('email_template', $data);
- and -
$this->handlebars_parser->parse('blog_template', $data);

If 3rd party code assume you are using there chosen "parser" how will they work together?
I assume they will both just use.
$this->parser->parse('some_template', $data);
but this won't work for templates / plugins in different formats.

Maybe register template file extensions and/or folders as certain formats?

I hope this is clear?


At the moment, CI4 has you specify a Renderer in the Config\Services::renderer(), which assumes that a single Renderer will be used.
Your usecases are valid, and the reason I wanted to defer dealing with multiple engines until after out "basics" are in place. This Renderer would be the one used by the global view() function, but that doesn't mean you can't use other view generators elsewhere.

In the meantime, an external packages can be as just that, eg

[code]$myHandlebarPresenter = new \Something\Cool\TemplateEngine();

If a third party package uses a template engine for any of its job, that will continue to work - I don't see anything in CI4 that would prevent that. I see that as a good use of composer.

My plan for our ClassFormerlyKnownAsTemplateParser is to have it in the CodeIgniter\Views namespace, as a slightly beefier alternative to the "regular" view, and not as *any* sort of template engine.

And yes, when we get to it, something like registering template engines or file extensions or formats etc etc, would make powerful sense. I am just trying to keep things as simple as possible in the early stages Smile  I'm sure this will get clearer as development proceeds!

Messages In This Thread
RE: Opinion: Template Engine Integration RIP? - by ciadmin - 07-20-2016, 08:28 AM

Theme © iAndrew 2016 - Forum software by © MyBB