Wednesday, September 8, 2010

Smarty with symfony 1.4

For last more than two years we have been using symfony 1.0. We used symfony 1.2 also for some of the projects. Since it is official now that symfony developers are not going to support 1.0 and 1.2 version, I thought to give symfony 1.4 a try for one of my new project.

After installing symfony 1.4.6 and setting some config parameters. I was able to run my first page successfully. Now it was turn to enable Smarty plugin. I tried to install sfSmartyViewPlugin that I used with version 1.2. But I came to know that symfony 1.4 does not support sfSmartyViewPlugin. I googled and found that there is a sfSmarty3Plugin that should be used instead.

It took me a long time to make this plugin work since I was not able to find enough information on how to configure this plugin on net.

Here I am giving the steps that I followed in case someone needs it:

Prerequisite:

- sfSmarty3Plugin
- Smarty3

1. extract sfSmarty3Plugin in plugin/ folder

2. vi config/ProjectConfiguration.class.php and add
$this->enablePlugins('sfSmarty3Plugin');
in the setup function

3. vi plugins/sfSmarty3Plugin/config/settings.yml and set

allow_php_tag: true #TO ALLOW THE OLD STYLE
lib_dir: lib/vendor/smarty/libs # path to the Smarty.class.php
left_delimiter:'{' # change it if you do not use default one
right_delimiter: '}' # change it if you do not use default one

4. vi config/module.yml

  default: # For all environments
    enabled: true
    is_internal: false
    view_class: sfSmarty
    partial_view_class: sfSmarty

5. In module.yml of each app

  default: # For all environments
    enabled: true
    is_internal: false
    view_class: sfSmarty
    partial_view_class: sfSmarty

6. In app.yml in each of app

  # default values
  all:
    sfSmarty:
      class_path: lib/vendor/smarty/libs # path to the Smarty.class.php
      template_extension: .tpl
      template_security: false

7. rename layout.php to layout.tpl

8. Make changes in settings.yml related to smarty configs

6 comments:

  1. Thanks a lot. It saved us.

    ReplyDelete
  2. Heyho :) Could you please give me a short confirmation if this this really works in a production environment? Thanks in advance :)

    ReplyDelete
  3. yes, at least it worked for me. My appl is working fine in production.

    ReplyDelete
  4. Sry, but what does nr. 8 means? What kind of changes i have to to do in settings.yml?

    ReplyDelete
  5. settings related to smarty like smarty_path, smarty_lib_path, smarty_lib_path, smarty_cache_dir, smarty_helpers etc.

    ReplyDelete
  6. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u


    Symfony Development

    ReplyDelete