Welcome Guest, Not a member yet? Register   Sign In
Twiggy - Twig template engine implementation
#1

[eluser]Edmundas Kondrašovas[/eluser]
Hey everyone,

I'm somewhat a big fan of Twig and I've been using it for quite some time now in my CodeIgniter applications. Therefore I decided to release my implementation of Twig for CI and share it with everyone.

In a nutshell, Twiggy is not just a wrapper for Twig. I added some neat functions to make life easier when dealing with themes, templates and layouts.

Github page: http://edmundask.github.com/codeigniter-twiggy/

I also created a demo (example) application to show how it could be used. I'll update it by adding more examples and documenting them.

Demo (example) application: https://github.com/edmundask/codeigniter-twiggy-demo

Let me know if you find it useful. Smile
#2

[eluser]Amine[/eluser]
I get the error message when I try to use demo :Fatal error: func_get_args(): Can't be used as a function parameter in C:\xampp\htdocs\CI-twiggy\sparks\Twiggy\0.8.3\libraries\Twiggy.php on line 154
#3

[eluser]Edmundas Kondrašovas[/eluser]
Try to clone the repository again, it should work now. It probably has something to do with your server setup. If it fixes the problem, I'll update the main repo (twiggy spark) as well.
#4

[eluser]Amine[/eluser]
I try to clone the repository,I have the same error message Confused
Fatal error: func_get_args(): Can't be used as a function parameter in C:\xampp\htdocs\CI-twiggy\sparks\Twiggy\0.8.4\libraries\Twiggy.php on line 154
#5

[eluser]Edmundas Kondrašovas[/eluser]
I only updated the demo app, not the spark repository: https://github.com/edmundask/codeigniter...6f0dc34933

You're using Twiggy v0.8.4 while the demo app is using v0.8.3 (for the time being), so I assume you're doing some testing of your own. You can look at the commit that I've posted here and change a few lines of code yourself to get rid of the error. I'll roll out Twiggy v0.8.5 with some updates, including this fix, soon and update the demo app as well.
#6

[eluser]Amine[/eluser]
It works,thank you so very much for the good work :d
#7

[eluser]Unknown[/eluser]
Great work on Twiggy.


How do you incorporate existing CI views into Twiggy.

For example: If I want existing CI views to be the html body and I want headers and footers driven by Twiggy.




#8

[eluser]Edmundas Kondrašovas[/eluser]
You should take a look at Output class: http://ellislab.com/codeigniter/user-gui...utput.html

I'm sure that you could pull something off with
Code:
$this->output->get_output();
and
Code:
$this->output->append_output();
$this->output->set_output();
methods.

However, I don't really recommend using both standard views and twig templates on the same page. Of course, it depends on what you're trying to accomplish but to me it seems like an overkill.
#9

[eluser]Unknown[/eluser]
Nice work !
I'm a bit new to CI and Twig, but achieved to make your twiggy working at least for the demo structure.
What I don't get is how I can use this to create several "template" folders (not files only).

Actualy the app only work inside "themes/default" folder and I want to be able to select a "template" not by a file but by a folder.

At the end the themes folder would look like :
theme :
- default :
- index.html.twig
- layouts :
- index.html.twig
- my_template :
- …
- another_template :
- …

Is this behavior even possible or did I get wrong on the whole template engine mechanism ?
I'm really new to this framework thing so I may be asking dumb questions sorry.

My only controller is home.php, it is set in the config routes, and it looks like :
Code:
class Home extends CI_Controller {

public function index()
{
  $this->load->spark('twiggy/0.8.5');
  $this->twiggy->theme('my_template');
  $this->twiggy->display();
}
}

I was happy to find some function to set the template in the twiggy core file but it didn't help much. I guess we're not referring to the same thing with the word "template". I want it to be able to choose between several WEBSITE template (themes folders) when twiggy look for files inside the themes/default folder.

If you can help here, I'll appreciate Smile
#10

[eluser]Unknown[/eluser]
Hi CreeAll,

I found solution for change theme.

Open file "sparks/Twiggy/0.8.5/libraries/Twiggy.php" and chnage some code in private function _set_template_locations($theme)
line
Code:
$this->_template_locations[] = $loc . $this->_module . '/' . $this->_config['themes_base_dir'] . $theme;

to
Code:
$this->_template_locations = array($loc . $this->_module . '/' . $this->_config['themes_base_dir'] . $theme);

and line
Code:
$this->_template_locations[] =  $this->_themes_base_dir . $theme;

to
Code:
$this->_template_locations =  array($this->_themes_base_dir . $theme);




Theme © iAndrew 2016 - Forum software by © MyBB