TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Kohana 3 - Smarty module
  • Another smarty module that can be used as a replacement for Kohana::View.

    I must warn anyone that would want to use this; It was created with Smarty 3.0 alpha, it offers speed improvements over previous versions, makes use of exceptions and can only be run with PHP 5. The downside is that it's still an alpha release, bugs are bound to be in there.

    Any future updates will be included in the module.

    The repository and downloads are located at bitbucket: http://bitbucket.org/zenk0/kohana-3-smarty-module/

    I hope I can spark some interest in this module.
  • You might want to take a look at dwoo - a php5 version of smarty. There's already a ko3 version

    and there's a older 2.3 version around also.
  • I feel sorry for Dwoo, but now that Smarty turns to PHP5 proper OOP, it makes far less sense to adopt it IMHO. AFAIK, Dwoo implemented very few different features and advertised itself almost solely on being a php5 Smarty.

    @zenk0: It's a bit early in my project right now, but I might definitely be interested into this. Even if still in alpha, the beta is around the corner is going to be very stable.

  • I've created a new Smarty module for ko3 with a cleaner implementation that extends Kohana::View.
    Supports both Smarty2 and Smarty3.


    Have fun :-)
  • @dfox: I see what you did there, I wanted to keep smarty's own way of doing things instead of adding support for Kohana::view. I use a different base controller so I didin't need to add support for Kohana::View.
    I wanted to make developers who use smarty feel home in kohana, the same goes for all the designers that taught themselves smarty syntax. It's a headache less when new people want to dive in Kohana.

    As you're my competition, I've added more configuration options and support for both smarty 3 alpha and smarty 2.6.26. Most of the changes can be read in the changelog on the wiki.

    @ccazette thanks for the support, I also agree with you on Dwoo. It's a good template engine, but it isn't frequently updated, which worries me. Smarty has a big community standing behind it.
  • @zenk0: Don't get me wrong - I like your approach very much, because there is practically no learning curve for existing smarty users. My approach is exactly the other way around - it should help existing kohana programmers to convert their views without having to modify their controller.

    I don't know if there will be many updates because it looks like it's working. Maybe I'll integrate some of my smarty-helpers, we'll see :-)
  • If you just want a stable implementaion of Smarty for Kohana 3, there is one at http://github.com/MrAnchovy/kohana-module-smarty.

  • @zenk0

    Can you elaborate about the 2 different ways of working with smarty.

    I mean which way is better, easier, standard etc.

  • Hello,


    in your page in smarty config file, it is written as:

    'template_dir' => APPPATH.'view'.DIRECTORY_SEPARATOR,

    shouldn't be

    'template_dir' => APPPATH.'views'.DIRECTORY_SEPARATOR,

    note: the 's' in view.
  • I think mine is the best (well I would say that, wouldn't I). Why?

    • easy to install from zip/tgz package
    • no configuration needed (but lots possible), works right out of the box
    • use for a view just by changing the template name (and writing the smarty template of course!)
    • no need to modify controllers to switch the site over to a Smarty page template
    • can easily be used alongside PHP templates
    • no speed penalty if not using a Smarty template (eg AJAX action)
    • easy to integrate into existing KO3 application: start with one view and change as few or as many existing templates as you like
    • unmodified smarty object is available so can use $smarty->assign(), $smarty->fetch() etc. to port existing code in almost zero time

    I am not going to criticise anyone else's work but do note that currently zenko's only works for controllers not views and needs some changes to config and/or write permissions before it works. dfox's is more like mine, but could do with including the Smarty source in the zip/tgz package and it doesn't have privacy of template variables (so there might be weird problems converting a Kohana app) and doesn't make an unmodified Smarty object available so it might be harder to integrate an existing Smarty app.

  • I'm getting ready to 'ship out' a new version of my module tonight.

    The reason I created the extra smarty controller is because I wanted to add a few features that the normal Kohana_View did not have. But I might steal your Smarty:templatefile syntax for the normal view controller and put it in my next release.

    I've gotten most of the new features complete, they're all described here: tickets

    I still need to finish the validation errors plugin for smarty though. This new release does work out of the box.
  • As said here

    Shouldn't we all work together on this? I don't see the sense in developing three different modules that basically all do the same stuff. It's confusing for the people who want to use it. I'm all for diversity, but I don't like the "take mine, it's best" direction this is heading into.
  • I started developing the Smart-Twig-Open-Plus Templating module.

    I use the suffix 'Plus' to denote the superiority of my work and hope that it overtakes the Kohana Template Module Market (aka: KTMM) by storm.

    My module will combine all Smarty features + all Twig features + all Kohana view features + PHP native features + Dave's excellent Table Library and Navigation Library. I also added a ton of background graphics, javascript effects, and CSS code for those times when you just need to lay down a theme in seconds.

    A 'clone' feature crept in last night that lets you steal the HTML layout, CSS, and javascript of any url address. Time to copy those best looking sites!

    For your viewing pleasure, I present three sites designed using Smart-Twig-Open-Plus Templating (STOP Templating). They make full use of pre-packaged effects and backgrounds.

  • I would SO LOVE for both Table and Nav to be used on Forever Forgiven! I'd be honoured if you could set a callback to make backwards galloping panthers appear in all Table cells :)
  • Finally a good solution for EVERYTHING!
  • @dfox could you link me again? the link doesn't seem to work.
  • Whats the status on the smarty modules your all working on? Are any stable? And can you use the cache featrues such as is_cached() easily?
  • Very good module. But its better to use signleton of Smarty class for accessing in other controllers.
    Just modify classes/smarty/smarty2.php (smarty3.php)

    class Smarty3 extends Smarty{
    private static $instance;

    public static function &getInstance() {
    self::$instance = new Smarty3();

    return self::$instance;

    and in classes/kohana/controller/smarty.php change:
    $this->view = new Smarty3();
    $this->view =& Smarty3::getInstance();

    This modification gives you advantage in creating auto loaded variables for Smarty in exctended controllers. For example in overloaded abstract class Controller extends Kohana_Controller {}
    when you want to load variable into a view but you cant do that now becouse your Kohana_Controller_Smarty extend from Cotroller and there isnt Smarty class set

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion