EllisLab text mark
Advanced Search
1 of 2
1
   
Twiggy - Twig template engine implementation
Posted: 24 March 2012 05:58 PM   [ Ignore ]
Avatar
Joined: 2007-07-22
69 posts

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

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 04 April 2012 01:44 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-06-08
3 posts

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

 
Posted: 04 April 2012 02:43 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

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.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 05 April 2012 10:36 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2011-06-08
3 posts

I try to clone the repository,I have the same error message :s
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

 
Posted: 05 April 2012 10:45 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

I only updated the demo app, not the spark repository: https://github.com/edmundask/codeigniter-twiggy-demo/commit/106de1751b048a7687e8556a9d49746f0dc34933

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.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 05 April 2012 11:33 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-06-08
3 posts

It works,thank you so very much for the good work :d

 
Posted: 01 May 2012 12:56 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-05-01
1 posts

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.

 

 

 
Posted: 02 May 2012 01:50 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

You should take a look at Output class: http://ellislab.com/codeigniter/user-guide/libraries/output.html

I’m sure that you could pull something off with

$this->output->get_output(); 
and
$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.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 17 June 2012 10:18 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2012-06-17
1 posts

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 :

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

 
Posted: 03 July 2012 06:27 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2012-07-03
1 posts

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

$this->_template_locations[] $loc $this->_module '/' $this->_config['themes_base_dir'$theme

to

$this->_template_locations = array($loc $this->_module '/' $this->_config['themes_base_dir'$theme); 

and line

$this->_template_locations[] =  $this->_themes_base_dir $theme

to

$this->_template_locations =  array($this->_themes_base_dir $theme); 
 
Posted: 30 August 2012 02:48 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Joined: 2009-12-16
40 posts

Hi,

how to display elapse_time and memory_usage in twig template?

thanks

 
Posted: 20 November 2012 12:19 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-11-19
3 posts

Duplicate post - please see below

 
Posted: 20 November 2012 12:20 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2012-11-19
3 posts

Hey great work on Twiggy.  I’m new to CI and having a bit of trouble figuring out how to implement.  I’ve downloaded your example code from:
Demo (example) application: https://github.com/edmundask/codeigniter-twiggy-demo

I’m having trouble understanding how I should modify a standard CI view to pull a template.

In your demo app, you have the “factory default”  welcome_message view.

It would be very helpful if you could repost the project with the welcome_message view using the twiggy template.

Or… a quick note on what changes are needed to the view / controller to pull the content properly.


Currently I have modified my view to just have the body content and have put the follow code in my welcome controller:

$this->load->view('welcome_message');
$this->twiggy->display(); 

I get the twiggy template rendered and then after the html close tag, the modified welcome_message - which is obviously not right.

Sorry about what I’m sure to be a very obvious oversight and ty for the help.

 
Posted: 24 November 2012 01:35 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2012-11-19
3 posts

So a couple things I figured out for all you other newbies.
1) A default non-wamp install of apache does not recognize .htaccess files which are required for most CI demos to remove the index.php.  Editing of the httpd.conf file is required.

2) urls to access the twiggy views in the demo app are:
/articles
/articles/view_with_sidebar

3) Actual twiggy logic for demo is found in:
/application/modules/articles/

4)  Forget about CI views with Twiggy.  Twiggy templates = CI views.

 
Posted: 12 January 2013 05:59 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2012-07-19
32 posts
helia_Dar - 24 November 2012 01:35 PM

So a couple things I figured out for all you other newbies.
1) A default non-wamp install of apache does not recognize .htaccess files which are required for most CI demos to remove the index.php.  Editing of the httpd.conf file is required.

2) urls to access the twiggy views in the demo app are:
/articles
/articles/view_with_sidebar

3) Actual twiggy logic for demo is found in:
/application/modules/articles/

4)  Forget about CI views with Twiggy.  Twiggy templates = CI views.

It seems this thread isn’t all that active any more, but just to clarify a bit on these points..

1) Whether .htaccess works or not has nothing to do with WAMP or LAMP, it relies on an Apache specific setting. If your (L/W)AMP stack is not obeying rules set in your .htaccess file, check the AllowOverride directive in your Apache configuration.

3) This is not because of Twiggy, but rather because the example in question uses Wiredesignz’s HMVC modification, you’ll see his files in the /application/third_party/MX/ folder.

4) Don’t forget about default CI Views, Twiggy templates != CI Views. As stated in the Twiggy readme file, it doesn’t replace the default methods, so you can still use them side by side without any problems. For example, for maintenance pages, “still under construction” pages or (if you use them) landing pages.

Hope that helps clarify things a little bit… And of course, happy Twigging. smile

 
Posted: 16 January 2013 03:57 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2012-07-19
32 posts

@Edmundas, hope you’re still watching this thread… I have a question regarding your Twiggy implementation of Twig. I’ve been trying to understand how the ‘_layouts’ folder fits into Twig, but I’m getting slightly confused here.

On your Twiggy page you give the example folder structure as:

+-{APPPATH}/
| +-
themes/
| | +-default/
| | | +-
_layouts/
| | | | +-
index.hml.twig
| | | +-index.html.twig 

Then the ‘index.html.twig’ file outside the ‘_layouts’ folder starts with:

{% extends _layout %

Looking at the Twig documentation (specifically this page), I can’t seem to find any examples of using ‘extends’ to reference a folder, only to reference files. Did you perhaps extend the ‘extends’ side in your implementation? Or am I perhaps missing some important point in the documentation?

Currently I’m running Twiggy with a folder structure of:

+-{APPPATH}/
| +-
themes/
| | +-default/
| | | +-
base/
| | | | +-
layout.hml.twig
| | | +-index.html.twig 

Then starting my index.html.twig file with:

{% extends "base/layout.html.twig" %

This works perfectly for me, but I can’t help but wonder if I’m missing out on some fancy feature here…

 
1 of 2
1