lonnieezell / Bonfire

Jumpstart your CodeIgniter web applications with a modular, HMVC-ready, backend.
http://cibonfire.com
1.39k stars 524 forks source link

Using a template engine ? #549

Closed hardfire closed 11 years ago

hardfire commented 12 years ago

are there any such plans, like maybe twig or something similar ? I think it helps a lot in the views.

lonnieezell commented 12 years ago

There's nothing firm in mind at the moment. The thought that's been in the back of my head, though, is that we'll likely need to create our own that takes the place of the parser that already exists. This would work with the existing template library. Here's my (small) wishlist:

So, that's what's been tickling the back of my mind for a while, though we've never set anything firm. If you wanted to work on something like that, it would be awesome.

hardfire commented 12 years ago

Hey yeah! This seems really impressive, especially the module interface, would just make life easier. I'd love to work on something like this, just a push in the right direction would help. Let me see how things are done most efficiently though..

Mostly we might have to set the template engine something like

Template::engine('engineName');

Then eventually, the template would load the proper engine and do the magic :)

lonnieezell commented 12 years ago

I know that in PyroCMS they had Dan Horrigan write up a nice parser that they use for their template lib. Don't recall the specifics of their implementation or their licensing at the moment, but it should provide the basics for writing a new parser.

hardfire commented 12 years ago

Aha! now i see where you get the module idea from. Pyro seems pretty impressive, looking at it.

lonnieezell commented 12 years ago

And here's Dan's Lex library, which is what Pyro uses:

https://github.com/fuelphp/lex

hardfire commented 12 years ago

Currently, how do we call a module method from a template ?

lonnieezell commented 12 years ago

Currently everything like that would happen through HMVC, so it would be something like:

<?php echo modules::run('module/controller/method', $params, $...); ?>

See their wiki for more info: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

Lonnie Ezell http://cibonfire.com - Kickstart your CodeIgniter app development http://TheNextRead.com - Serialized Fiction for the entrepreneurial author http://LonnieEzell.com - Web Mechanic, Fantasy Author, Musician

On Fri, Aug 24, 2012 at 10:21 AM, Avinash Kundaliya < notifications@github.com> wrote:

Currently, how do we call a module method from a template ?

— Reply to this email directly or view it on GitHubhttps://github.com/ci-bonfire/Bonfire/issues/549#issuecomment-8004481.

og-shawn-crigger commented 12 years ago

Inside of a Controller you can use

$this->load->module('module/controller');

$this->module->method();

Inside a view would be like Lonnie stated above.

Back on topic, Has anyone tried SImpleTags for a templating library?

hardfire commented 12 years ago

Have not tried SimpleTags Did try blade templating library used in laravel and it is pretty elegant. So is twig. :)

og-shawn-crigger commented 12 years ago

Simple Tags

I haven't tried it yet but it seems pretty Simple and better then the stock parser, which btw causes issues with our Template library

hardfire commented 12 years ago

Ok, i have done some progress here. i created a parser, that calls Dan's lex library, pretty similar to what has been done in pyrocms.. (learned a lot there)

things are working and we can also call modules like {mod:user:list limit="10" offset="10"} , though the arguments name are useless, they are passed squentially to the method.

Only issue right now is when the module is also using the parser it goes into an infinite loop... will push the code as soon as i fix it or i think i need some help, whichever comes earlier :)

og-shawn-crigger commented 12 years ago

I ran into some issues with the parser and the template engine going into a loop and dieing, I pushed a fix yesterday for the default parser yesterday

hardfire commented 12 years ago

This one right? https://github.com/ci-bonfire/Bonfire/issues/547 . will check soon!

hardfire commented 12 years ago

ok, here is my parser class https://gist.github.com/3496437 .. most of it is pretty obvious. the issue here is that when i have a view like

{{ module2:method }}

and the module2 method also calls the parser, the parser calls the view for the original module and not module2 It is mostly because when the parser calls

$CI->load->view ...

It is in the context of the original module and not module2. Any Suggestions ?

hardfire commented 12 years ago

@svizion somehow after this fix, the template is working but $data is not being passed to the parser, its null ... looking into that right now ..

og-shawn-crigger commented 12 years ago

Yikes dangit! I think I know why, just not quite sure the fix to it yet, I'll take a look into it tonight, I actually found another bug in bonfire I've been lookin at today that's been annoying the hell outta me

hardfire commented 12 years ago

Ok! good news. Things are working .. This is the view that i have used as a test for now ..

<h2>Hello {{ name }}</h2>
{{ news:index name='Don' }} 
{{ news:awesome }}

<h2>Hello {{ name }}</h2>

<ul>
{{ posts }}
    <li> {{ title }} - {{ id }} </li>
{{ /posts }}
</ul>

<ul>
{{ news:latest }}
    <li> {{ date }} - {{ name }} - {{ id }} </li>
{{ /news:latest }}
</ul>

and i must tell it WORKS! :) I'll do some more tests and then push it asap.

lonnieezell commented 12 years ago

That's awesome. Thanks so much! Sounds like a great addition.

We are getting ready for a push on the 0.6 branch to official, so this might get pushed off for the 0.7 release, but unsure currently.

hardfire commented 12 years ago

I made a push in a (branch) [https://github.com/hardfire/Bonfire/tree/templateEngine] on my forked repository. Please have a look and let me know of the issues, if any comes up.

og-shawn-crigger commented 12 years ago

Did you get it to parse more then just a single view file or are we still stuck at that issue?

hardfire commented 12 years ago

Ok, for that i am thinking of creating a template function for module methods that would work as widgets as such, Right now i have been loading them as simple views.

hardfire commented 12 years ago

One more update. now we can call libraries too ... so this would work.

{{ Assets:image path='assets/images/image.jpg' }}
pierresilva commented 12 years ago

OK, I found this package https://gist.github.com/3802666 and works for me... thank you very much to dhorrigan, hardfire and svizion his library is awesome...

pierresilva commented 12 years ago

Hello, just one more thing. when I load the view from the themes folder is not parsed. I want my view from themes> mytheme> pages> view.php

When the view is loaded from modules> pages> views> view.php works well.

How to fix this?

lonnieezell commented 11 years ago

This has been incorporated into the latest develop branch push, and it fixed the issue with themed views not being parsed, I believe. Please give it a thorough run through if you have the time. I haven't had a chance to do thorough testing on it yet, but I'm sure I will be as I write up some docs for it.

mwhitneysdsu commented 11 years ago

Are you still in the process of pushing that, or am I just looking in the wrong place for it?

lonnieezell commented 11 years ago

Woops. Didn't notice the error that the push threw up. Fixing a merge conflict then it will be pushed momentarilly.

lonnieezell commented 11 years ago

Okay, they should be there now. Sorry about that.

hardfire commented 11 years ago

oh! wow, looks like the MY_Parser.php I once wrote is in use, awesome! I will also have a look and run some tests.

lonnieezell commented 11 years ago

@hardfire Yup! Thanks so much for the code, it seems to work great so far! Let me know if you run into any issues, otherwise I will mark this one as closed.