Hi All,
I need to add custom modules field in Email template.
How can I map or add the custom module fields in Email template
Hi All,
I need to add custom modules field in Email template.
How can I map or add the custom module fields in Email template
Hi,
I got here asking myself (and google) the same question. Sorry for the >1 year post.
Adding the custom field to database works fine, but I did not see a way to add the field to the Edit view, other than editing SugarCRM core files.
There is no editviewdefs.php file, it is done in what I suppose is an older way, using html templates.
The list view however is more up to date. I could add the custom field to it and use massupdate to change its value.
Not very efficient but it might work for my limited needs, it won't be used very often.
Still, if anyone can share a way to edit the EmailTemplates record view without changing core files I would very much like to know how to do it :)
Stay safe,
Laurent
Hi,
I got here asking myself (and google) the same question. Sorry for the >1 year post.
Adding the custom field to database works fine, but I did not see a way to add the field to the Edit view, other than editing SugarCRM core files.
There is no editviewdefs.php file, it is done in what I suppose is an older way, using html templates.
The list view however is more up to date. I could add the custom field to it and use massupdate to change its value.
Not very efficient but it might work for my limited needs, it won't be used very often.
Still, if anyone can share a way to edit the EmailTemplates record view without changing core files I would very much like to know how to do it :)
Stay safe,
Laurent
Laurent (and Sino Thomas the OP),
Sorry for the long reply, and for the detailed nature if you already know most of this, but you did ask :)
You are right that the Email Templates uses an older method for display / edit of the form and data. I am guessing only real oldies like myself remember the way Sugar used to be in the pre-v.5 days ;) It is possible to adjust these layouts in a custom-safe-ish way though (as with all older dev work, if this module gets changed to Sidecar then you will lose all dev stuff and have to re-create it using the Sidecar model).
Anyway, the really old method even pre-dates the use of the editviewdefs files and is based on (Smarty?) templates. These use separate .html and .php files to create the layouts and populate the forms. In short, there are pairs of files that create these, they are split into Detail and Edit views and are named accordingly. You are looking for files named DetailView.php and DetailView.html which you will find in the module directory for EmailTemplates. There are equivalent Edit versions of these as well. The old system allows you to make copies of these in the appropriate ./custom directory to create your own custom versions of the layouts. This applies to all modules, not just EmailTemplates however, all others have been superseded by the viewdefs and latterly by the clients/{platform}/{view}/... model. Further, and specific to the EmailTemplate module, you will find an additional file called "EditViewMain.html" - this is used in conjunction with "EditView.html" to provide alternate layouts based on the source of the email template. I'll explain further on that in a moment. For now you need to simply copy the existing stock files into the equivalent ./custom directory and edit them there.
What you really need here now is to grab a copy of the developer guide for Sugar version 4.5 or thereabouts. Unfortunately, you are unlikely to find such a guide in the SugarCRM.com pages as it is so old. There are a couple of books that help you understand this development model if you are interested though. Or you may find a kind soul who has kept an old copy of the dev guide. I am pretty sure I deleted mine a while back thinking it was useless So in the absence of a full dev guide I'll try to give a couple of pointers. The rest should not be tricky to work out, it is only PHP and HTML templating after all.
First, the .php version of these files do the grunt work of collecting the data from the DB and getting it ready to show / edit. They also specify the layout file to be used. They set up and fill in a template using the XTemplate class, you will normally find the line which does this using:
$xtpl = new XTemplate({path-to-template-file]);
In the case of this Email Template, the EditView.php has a condition here, it uses different layout files depending on a couple of items. You will easily find this and see what is happening. Basically here though you create the template based on the "*View.html" layout you wish to use. In your ./custom version of the .php file you will need to specify the custom directory path to the layout file. So for the custom edit view it would read:
if ($has_campaign || $inboundEmail) {
$xtpl = new XTemplate('custom/modules/EmailTemplates/EditView.html');
} else {
$xtpl = new XTemplate('custom/modules/EmailTemplates/EditViewMain.html');
}
Within the PHP file you will also find that variables for use in the layout are defined. There are lots of these in the format:
$xtpl->assign({VARIABLE}, {value});
and this is where you assign things like field values for display in the DetailView and initialisations of fields for the EditView. These variables are then referenced in the layout to pull the data that the PHP code has created / retrieved.
Now you need to adjust the custom version of the HTML layout template which is what actually makes the visible changes in the forms / pages. For the Detail View these only need go in the custom DetailView.html file but for the Edit version you will probably need to make changes in both EditView.html and EditViewMain.html - the latter is most likely what you are requiring here.
This .html file is quite simple in that it is just a HTML layout of what you see on the screen. No real explanation of the layout needed here I hope. It is pure HTML though so you will see that things like hidden field elements are described that handle return paths and data passed into the POST form for record and module for example. The bits you will need to concentrate on and adjust are where your new custom field is placed. You will need to create new table rows (I said it was old!!!) and define the HTML element markup for them. You can here, as you see from existing markup, use the variables you defined in the .php file to bring data into the layout. I am not going to go into that as this is all quite straightforward if very old-fashioned.
Finally, the trusted QR&R is needed to bring the custom files you create into the cache. Et voila! Your changes will automagically appear
I suppose I could have simplified all the above into "make custom copies of the stock files and edit them there" but that removes the fun of going back over the old development techniques!
Hopefully this is easy enough to follow and helps you or others. Been interesting to think about the olden days again.
Good luck.
JH.