Smarty or PHP as a templating language?

bsoremsugar —  February 12, 2010 — 7 Comments

Just came across an interesting post by Ibuildings CTO Ivo Jansch, talking about the use of Smarty as a templating language over PHP itself. His argument comes down to the the cleanliness of the code; he considers Smarty code much easier to read and follow when used inside a PHP script as compared to PHP itself.

SugarCRM uses Smarty extensively as a part of our metadata, themes, and MVC frameworks to help separate the markup from our PHP code, and have built in several optimizations to our use of Smarty to avoid some of the speed penalties from using it. What does everyone else think about using Smarty as a templating language? Sound off in the comments with your thoughts.

7 responses to Smarty or PHP as a templating language?

  1. 

    I do like Smarty and it’s capabilities and I think Sugar made a Smart(y) move by choosing to use it. It would be nice to see all Xtemplate code and the Xtemplate library itself removed from the next major release.

    By the way, I found the examples used by Ivo Jansch to be a bit self-serving to fit his article. That PHP code could have been better.

  2. 

    I do like Smarty and it’s capabilities and I think Sugar made a Smart(y) move by choosing to use it. It would be nice to see all Xtemplate code and the Xtemplate library itself removed from the next major release.

    By the way, I found the examples used by Ivo Jansch to be a bit self-serving to fit his article. That PHP code could have been better.

  3. 

    I don’t like Smarty. Adding conditions and logic into a template just adds a layer of complexity and makes the template engine run slower. I’d much rather Sugar had stuck with XTemplate and kept logic and HTML apart, and not required the annoying workarounds for Smarty’s inability to handle escaping properly.

  4. 

    I don’t like Smarty. Adding conditions and logic into a template just adds a layer of complexity and makes the template engine run slower. I’d much rather Sugar had stuck with XTemplate and kept logic and HTML apart, and not required the annoying workarounds for Smarty’s inability to handle escaping properly.

  5. 

    I have to agree with David on this, I’ve always felt the template engines should be used for parsing content, specifically.

    Adding in the additional fuss from a whole programming language just adds to the page load.

    Also, I feel like, in some cases, it can result in even more “unclean” code because of the way customizations may have to be done on certain modules or included objects.

    For example, I just customized the ‘Datetimecombo’ object adding the ability to set a default time. It was quite daunting to have to code between PHP, JavaScript, basic HTML, and the Smarty engine. I know for a fact that the solution I came up with was not as efficient or UI friendly as I would have hoped for.

    That’s not to say Smarty is useless or doesn’t work. Just feel it to be a bit too deep into the logic side of things, rather then focusing on better parsing procedures.

  6. 

    I have to agree with David on this, I’ve always felt the template engines should be used for parsing content, specifically.

    Adding in the additional fuss from a whole programming language just adds to the page load.

    Also, I feel like, in some cases, it can result in even more “unclean” code because of the way customizations may have to be done on certain modules or included objects.

    For example, I just customized the ‘Datetimecombo’ object adding the ability to set a default time. It was quite daunting to have to code between PHP, JavaScript, basic HTML, and the Smarty engine. I know for a fact that the solution I came up with was not as efficient or UI friendly as I would have hoped for.

    That’s not to say Smarty is useless or doesn’t work. Just feel it to be a bit too deep into the logic side of things, rather then focusing on better parsing procedures.

  7. 

    Hi John,

    I know my below queries not exactly belong to this post, but you have resolved most my problems so, I am asking this which related to custom template in sugarcrm 6.4 CE.

    I have a custom module without any database table or bean for example ordersearch and in this module I have an action named action_search.

    Controller Code is:
    class ordersearchController extends SugarController {
            public function  action_search(){
            $mobileNumber=$_GET['mobile'];
            $accountFocus = new Account();
            $accountFocus->retrieve_by_string_fields(array(‘phone_office’=>$mobileNumber));
            $this->view = ‘search';
        }
    }In this action, I am including a custom view named search (view file exists in modules/ordersearch/views/view.search.php ) and I have a custom template file for this view also (template file exits in modules/ordersearch/tpls/search.tpl).View file: view.search.php  Code:class fab_OrdersearchViewSearch extends SugarView{

            function fab_OrdersearchViewSearch() {
                    parent::SugarView();
            }
            function display() {
                    echo “Hello World :”;
                    parent::display();
            }
    }Template file Code:HrishikeshMy custom view file is working properly i.e I am not getting any error for view. But I am clueless where and how to 
    include or call this custom template file what will be code for this or should I have to create some other files also like metadata/searchdefs.php etc (but if so then what will be their code). And how can I assign variable to show in that custom template file through controller’s action. I have posted this query to various place but till not get any response. Please help me. Waiting for responseHrishikesh Mishra 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s