Results 1 to 4 of 4

Thread: custom php code in .tpl file

  1. #1
    dskanth is offline Senior Member
    Join Date
    Mar 2009
    Posts
    97

    Wink custom php code in .tpl file

    Is it possible to write php code inside a .tpl file ?
    I see that the tpl files are automatically created, but i need to write some php code in them.

    So is there any way i can achieve this?
    Please guide me, as i need to write some condition in tpl file using php.

    Your help is much appreciated.

  2. #2
    crmbalah is offline A Prolific Poster
    Join Date
    Mar 2009
    Location
    chennai
    Posts
    418

    Default Re: custom php code in .tpl file

    Hi
    If you customize the code inside the .tpl file, that’s not safe.
    If you customize the .tpl related view throw the studio, the tpl files are replace.
    You try to customize the listviewdef,editview def,etc.. files

  3. #3
    dskanth is offline Senior Member
    Join Date
    Mar 2009
    Posts
    97

    Default Re: custom php code in .tpl file

    hai, thank you for your response, but we need to hide the fields in the panel, based on a condition (like whether an admin or user has logged in). So can you suggest a way to do this ?

    Thank you.

  4. #4
    lucasnomail is offline Member
    Join Date
    Nov 2009
    Posts
    15

    Default Re: custom php code in .tpl file

    Hi SugarCRM uses smarty therefore this would do your thing

    Code:
    {php}
         echo 'This will be sent to browser';
    {/php}
    But to try make conditions based on given user, goes against MVC logic. Just read bit more about sugarCRM before you will do this to your poor templates.
    Make your own controller.php in module folder . (but you have to dig elsewhere to find answer for that, pages 15.-18. from book The Definitive Guide to SugarCRM holds the answer to that) But depends really on situation controller or your own module where you can decide what to show, or set. Template can react to that but don't put php to template that is just ugly.

    following is more sugar specific template but you might get the idea
    Code:
    {{assign var='some_sys_var_c' value=0}}
    {php}
    $fieldValue = $this->_tpl_vars['some_sys_var_c'];
    echo $fieldValue;
    {/php}
    you can read more about it http://www.smarty.net/manual/en/lang...nction.php.php
    Last edited by lucasnomail; 2010-01-18 at 10:54 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. custom function call from custom code field in metadata
    By josh.sweeney in forum Developer Help
    Replies: 9
    Last Post: 2010-02-09, 09:23 PM
  2. Odd code in english language file
    By SugarDev.net in forum Developer Help
    Replies: 0
    Last Post: 2008-09-30, 09:50 AM
  3. Replies: 0
    Last Post: 2008-07-14, 04:40 PM
  4. Php code in Xtemplate template file
    By incredible in forum Help
    Replies: 5
    Last Post: 2006-02-22, 06:50 PM
  5. config.php file. use DEFINE() and not hard code it.
    By djtremors in forum Feature Requests
    Replies: 0
    Last Post: 2006-01-17, 07:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •