Changeset 14326
- Timestamp:
- 12/26/08 01:12:40 (4 years ago)
- Files:
-
- plugins/sfSmartyPlugin/trunk/README (modified) (6 diffs)
- plugins/sfSmartyPlugin/trunk/package.xml (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSmartyPlugin/trunk/README
r14317 r14326 1 = sfSmarty plugin = 1 sfSmarty plugin 2 =============== 2 3 3 == Overview == 4 ## Overview ## 4 5 5 6 This plugin gives you the ability to use the Smarty templating engine for your view templates. 6 7 http://www.smarty.net 7 8 8 == Installation == 9 ## Installation ## 9 10 10 To install sfSmartyPlugin: 11 #### sfSmartyPlugin #### 11 12 12 Checkout the plugin from the SVN repository http://svn.symfony-project.com/plugins/sfSmartyPlugin/trunk 13 Checkout the plugin from the SVN repository http://svn.symfony-project.com/plugins/sfSmartyPlugin/trunk, download and install the pear package or via symfony plugin install. 13 14 14 Its currently the best working copy. 15 16 15 #### Smarty #### 17 16 You must also install Smarty (http://www.smarty.net) 18 17 … … 23 22 It can be checked out from the Smarty SVN repository here, http://smarty-php.googlecode.com/svn/tags/Smarty_2_6_22/ 24 23 24 ## Configuration ## 25 Once you have installed smarty, you must edit the app.yml in each of your applications that you intend to use the smarty engine. 25 26 26 Once you have installed smarty, you must edit the app.yml in each of your applications that you intend to use the smarty engine. 27 {{{ 28 # default values 29 all: 30 sfSmarty: 31 class_path: lib/vendor/smarty/libs 32 template_extension: .tpl 33 template_security: false 34 }}} 27 # default values 28 all: 29 sfSmarty: 30 class_path: lib/vendor/smarty/libs 31 template_extension: .tpl 32 template_security: false 33 35 34 The Smarty.class.php file is located under your smarty/libs folder. Thus the /libs on the end of the class_path. 36 37 35 38 36 Clear the cache to enable the autoloading to find the new classes: 39 37 40 41 == Versions == 38 ## Versions ## 42 39 43 40 This plugin is intended for Symfony 1.1 or 1.2 Only. 44 41 45 46 == Usage == 42 ## Usage ## 47 43 48 44 Smarty is considered one of the best templating engines for PHP. … … 50 46 51 47 If you intend to use Smarty as the default templating engine, edit your project root/config/module.yml file. (if it doesnt exist, create one) 52 {{{ 53 default:54 view_class: sfSmarty55 partial_view_class: sfSmarty56 }}} 48 49 default: 50 view_class: sfSmarty 51 partial_view_class: sfSmarty 52 57 53 From then on all template files ending with .tpl (or whatever extension you set during installation) will be processed with sfSmarty. 58 54 … … 61 57 You can still utilize .php templates as the plugin will now check the extention of the template and use the appropriate renderer. 62 58 59 sfSmartyPlugin also contains a settings.yml in its config folder. Suggest leaving this alone. 63 60 64 sfSmartyPlugin also contains a settings.yml in its config folder. Suggest leaving this alone. 65 61 ### Templates ### 62 When using Smarty as the default templating engine, you must also rename the default symfony layout.php file to layout.tpl 63 and then update it so it looks like this: 66 64 67 == Example Usage == 65 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 66 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 67 <head> 68 69 {include_http_metas} 70 {include_metas} 71 72 {include_title} 73 74 <link rel="shortcut icon" href="/favicon.ico" /> 75 76 </head> 77 <body> 78 79 {$sf_content} 80 81 </body> 82 </html> 83 84 Nice and Clean isnt it. =D 85 86 ### link_to_app ### 87 88 The link_to_app helper method will allow easy linking between applications 89 90 {link_to_app app='admin' name='Admin App Link'} 91 92 With Optionals 93 94 {link_to_app app='admin' name='Admin App Link' internal_uri='default/index' path='/admin/ subdomain=false} 95 96 From above the subdomain and path arguments will generally be used together. If you do not have your applications on separate subdomains then you would set subdomain to false and your path would have the web folder location of your application index scripts. The path argument MUST have a trailing AND leading slash. 97 98 ## Example Usage ## 68 99 69 100 sfSmarty will automatically attach sf_data, sf_context, sf_request, etc.. to the smarty vars. 70 101 71 102 These can be used as such: 72 {{{ 103 73 104 {$sf_data->get('arg')} 74 }}} 105 75 106 76 107 Any variable in an action that is assigned to $this is also available, for example in the action: 77 {{{ 108 78 109 $this->var = 'foobar'; 79 }}} 110 80 111 Can be used in the template as: 81 {{{ 112 82 113 {$var} 83 }}}84 85 This is typical Smarty. All values are currently assigned (and thus copied), this will be updated as soon as possible to assign_by_ref (assigned by reference).86 87 The smarty vars (sf_data, sf_context, ..) are currently assigned by references.88 114 89 115 116 This is typical Smarty. All values are assigned by reference to Smarty. 117 The smarty vars (sf_data, sf_context, ..) are also assigned by references. 118 119 ### Smarty Methods ### 90 120 Smarty internal functions for looping and conditions work as is and should be used. 91 {{{ 121 92 122 {foreach from=$arr item='item'} 93 123 My item is {$item} 94 124 {/foreach} 95 }}} 125 96 126 Refer to the Smarty documentation. 97 127 128 The Javascript helper tag is also available and must be used as such: 98 129 99 The Javascript helper tag is also available and must be used as such:100 {{{101 130 {javascript} 102 131 function someFunc() {ldelim} … … 104 133 {rdelim} 105 134 {/javascript} 106 }}} 135 107 136 Because the braces have a specific use in Smarty. It is suggested (of course) that the bulk of your javascript should be in javascript files which are attached when needed. Keep template javascript to a minimum. 108 137 138 To attach helpers: 109 139 110 To attach helpers:111 {{{112 140 {use helper='Javascript'} 113 }}} 141 114 142 The {use} tag does not accept an array of values currently. 115 143 144 Smarty can also be utilized within actions via static calls. In an action: 116 145 117 Smarty can also be utilized within actions via static calls. In an action:118 {{{119 146 $smarty = sfSmarty::getInstance()->getSmarty(); 120 147 $smarty->register_object('foobar',$myobj); 121 }}} 148 122 149 $foobar will then be available as an object reference in your template. 123 150 124 125 == Final Notes == 151 ## Final Notes ## 126 152 127 153 I have tried to optimize certain methods and have cleaned up some from the last 0.12 release. … … 131 157 It may even be possible to store the references to these compiled templates to have the sfPHPView load them directly which reduce template rendering time a little further. 132 158 133 134 159 Symfony view caching can be used together with sfSmarty but it is not suggested to combine Symfony view cacheing with Smarty view caching as it is just extra overhead. Both cached files would be essentially the same. plugins/sfSmartyPlugin/trunk/package.xml
r14319 r14326 14 14 <time>06:34:35</time> 15 15 <version> 16 <release>0.2. 2</release>16 <release>0.2.3</release> 17 17 <api>1.0.0</api> 18 18 </version> … … 68 68 <release> 69 69 <version> 70 <release>0.2. 2</release>70 <release>0.2.3</release> 71 71 <api>1.0.0</api> 72 72 </version> … … 81 81 <license>MIT</license> 82 82 <notes> 83 * insaini: Updated README, fixed caching with old partial view class, optimized renderFile and load helpers methods, and allowed rendering of .php via parent class automatically. 83 * insaini: - Updated link_to_app helper method for correct behaviour between environments 84 - Updated sfSmarty to assign_by_ref all values from the view 85 - Updated sfSmarty to correctly select the renderer for the layout. 84 86 </notes> 85 87 </release>