CodeIgniter Forums
Really Simple Smarty 3 Library for Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Really Simple Smarty 3 Library for Codeigniter (/showthread.php?tid=36313)

Pages: 1 2 3 4


Really Simple Smarty 3 Library for Codeigniter - El Forum - 11-28-2010

[eluser]Vheissu[/eluser]
I have written a super simple and hopefully somewhat helpful library for Codeigniter that lets you use Smarty 3 to render your views. It is compatible with the latest version of Codeigniter as all posts about Smarty integration into Codeigniter are about 3 years old mostly.

I am sure that most other libraries probably still work, but this is something super simple that lets you render a view using Smarty and assign variables the usual Codeigniter view loading way.

Read about it and get the code from my post: http://ilikekillnerds.com/2010/11/using-smarty-3-in-codeigniter-2-a-really-tiny-ci-library/

I am planning on making it a parser library extension, but don't really have the time. Feel free to critique my code and suggest perhaps even post improvements.


Really Simple Smarty 3 Library for Codeigniter - El Forum - 12-01-2010

[eluser]mohrt[/eluser]
FYI your library is featured on the Smarty home page Smile Some of you may be interested in Template Inheritance, a new feature of Smarty 3 that greatly improves the management of template/view files. See here for an explanation with an example.


Really Simple Smarty 3 Library for Codeigniter - El Forum - 12-01-2010

[eluser]Vheissu[/eluser]
[quote author="mohrt" date="1291239898"]FYI your library is featured on the Smarty home page Smile Some of you may be interested in Template Inheritance, a new feature of Smarty 3 that greatly improves the management of template/view files. See here for an explanation with an example.[/quote]

Lol, wow. Didn't expect that to happen. Gives me an incentive to actually make the library better and get off my butt. For anyone else's reference, template inheritance and all other Smarty 3 specific features work as intended.

I have included an example of how the library works as well as template inheritance for anyone interested in downloading Smile

The project for which I wrote this library for is heavily using template inheritance as we speak and it works awesomely.


Really Simple Smarty 3 Library for Codeigniter - El Forum - 12-01-2010

[eluser]Vheissu[/eluser]
An update:

In light of being featured on the Smarty page I got off my butt and updated the library. The one thing I hate about libraries is having to use propriety library names, so now to load views utilising this Smarty library you load them like you would normally via $this->load->view(); and it now supports returning the template data or displaying it.

Keep in mind that in the package I am using a MY_Loader to extend the view functionality, so if you are using Modular CI or Modular Extensions you might want to copy and paste the code into your file yourself or it could overwrite that functionality.


Really Simple Smarty 3 Library for Codeigniter - El Forum - 12-02-2010

[eluser]mohrt[/eluser]
Hmm, I wouldn't recommend bundling Smarty with your lib in this case. Keep your lib slim, and inform the user how to grab the latest Smarty and install it for themselves. Then you don't worry about falling behind in your bundled version, and the download is minimal.


Really Simple Smarty 3 Library for Codeigniter - El Forum - 12-02-2010

[eluser]Vheissu[/eluser]
[quote author="mohrt" date="1291367313"]Hmm, I wouldn't recommend bundling Smarty with your lib in this case. Keep your lib slim, and inform the user how to grab the latest Smarty and install it for themselves. Then you don't worry about falling behind in your bundled version, and the download is minimal.[/quote]

That initially crossed my mind, but from what I've seen it's a step people seem to screw up so easily. Perhaps I'll offer two versions, one with Smarty bundled and one without Smarty bundled.


Really Simple Smarty 3 Library for Codeigniter - El Forum - 12-15-2010

[eluser]Unknown[/eluser]
What would you say to using

Code:
$CI->smartyp->_assign_variables(array_merge($this->_ci_cached_vars, $vars));

instead of

Code:
$CI->smartyp->_assign_variables($vars);

in core/MY_Loader.php file.

That makes use of previously cached variables. And thanks for the library, made my life easier while migrating one of my applications to CI


Really Simple Smarty 3 Library for Codeigniter - El Forum - 01-30-2011

[eluser]Unknown[/eluser]
Thanks for putting this together, very useful.

What is the best practice for making Smarty the template engine for all my websites? Obviously I can copy over the MY_Loader.php and the other ones, and point the path for Smarty to some common directory, but is there a way to extend the CI Library WITHOUT changing the core? Since 2.0.0 is just out, I'll assume that there will be minor updates and I don't want to have to re-integrate my changes every time a new release comes out.

If not, I'll just add your files to the files I copy over whenever I'm making a new project, but wondered if there was a cleaner way.

Thx,

Tac


Really Simple Smarty 3 Library for Codeigniter - El Forum - 03-11-2011

[eluser]Alexander84[/eluser]
Current Smarty3 CI adapter outputs numerous warnings and notices if no $data is specified as argument in controller (common scenario when you just want to parse a couple of templates). To be more specific:

Code:
$this->parser->parse(“somepage.tpl”);

outputs as follows before template processing

Code:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for MY_Parser::parse(), called in somepage_controller.php on line 6 and defined
Filename: libraries/MY_Parser.php
Line Number: 22

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: libraries/MY_Parser.php
Line Number: 44

A PHP Error was encountered
Severity: Warning
Message: array_merge() [function.array-merge]: Argument #1 is not an array
Filename: libraries/MY_Parser.php
Line Number: 44

Could one be so kind and fix these gaps in adapter?

P.S.
Maybe library of Dwoo CI adapter (ci_dwoo_1_0_2.zip -> Dwootemplate.php) would inspire you
as well as Seldaek’s comment in thread about ampersand removal near $CI = get_instance().


Really Simple Smarty 3 Library for Codeigniter - El Forum - 03-11-2011

[eluser]Vheissu[/eluser]
The issue has been fixed and pushed to the repo Alexander. It was a simple fix of adding $data = '' to the parser function, must have forgot to add that part in because I was checking in the function if data has been supplied anyway.