CakePHP 1.3, Smarty 3, and Theming. Woohoo!

There are various solutions out there for integrating Smarty with CakePHP. I’m here to introduce another one, that I feel is a little leaner than the other solutions I’ve found.

Jump to the code: https://gist.github.com/672398

Requirements:

  • Cake 1.3.2 (No idea if it will work on < 1.3.2)
  • Smarty 3

Just place this in your /app/views folder andmake sure your AppController has the following lines:

public $view = "Theme";
public $layout = "default";
// The following line is optional; the default ext in the ThemeClass is set to .html.
// Uncomment to set to your desired extension
// public $ext = ".some_extension";

Your views would (unless you change the $ext variable) then be saved with .html extensions.

Leave a comment

3 Comments

  1. trevize pelorat

     /  November 11, 2010

    hi there! is it possible for you to explain this a little bit more? I have:

    – CakePHP 1.3.5 successfully installed
    – smarty 3 RC4 files in app/views/smarty
    – CakePHP1.3_Smarty3_Themeing.php as theme_view.php in app/views/themed
    – that two lines in cake/libs/controller/app_controller:
    public $view = “Theme”;
    public $layout = “default”;

    But I got this error:

    Error: The view for CentralController::index() was not found.

    Error: Confirm you have created the file: /home/pepito/public_html/fulanito/app/views/central/index.ctp

    And I have index.tpl in app/views/central

    Thanks!

    Reply
    • Jen

       /  November 11, 2010

      Hmm…perhaps make sure you have added public $ext = ‘.tpl’; to your app_controller or change the code in the Theme View class you added? Looks like I forgot to add that when I originally wrote this post; I’ve updated it to reflect that.

      Reply
  2. random_stranger

     /  March 17, 2011

    Last comment was a while ago, but worth mentioning if anyone else come across this via Google like I did:

    Make sure to rename CakePHP1.3_Smarty3_Themeing.php to theme.php in your views folder. Thanks for the great post btw, Jen!

    Reply

Leave a comment

  • Design a site like this with WordPress.com
    Get started