Another customCode Question for Smarty Templates

I’m making good progress and have been to output almost every field type with this method. However, the assigned user eludes me! I’ve tried a bunch of different syntax and just can’t get it to work.

@p.konetskiy I know you are a guru on this topic, hopefully you can chime in. I’ve learned alot from your posts!

I’m trying this and it just won’t work. I’m thinking it should! What am I doing wrong here (this is in the opportunities module)

 0 => 
          array(
		  'name' => 'assigned_user_name',
		 'customCode' => '{if $isAdministrator}@@FIELD@@{elseif $fields.sales_stage.value eq "Closed Won" || $fields.sales_stage.value eq "Closed Lost"}
				<span>{$fields.assigned_user_name.value}</span>
				{else}@@FIELD@@{/if}',
		  ),

Everything works as expected, except outputting the user name as a value.

Ok so got to the bottom of it. The above code does work… thanks @p.konetskiy I got it from one of your old posts.

This works a bit better because it doesn’t show the entry box (input):

'customCode' => '{if $isAdministrator}@@FIELD@@{elseif $fields.sales_stage.value eq "Closed Won" || $fields.sales_stage.value eq "Closed Lost"}
				<span>{$fields.assigned_user_name.value}</span>
				{else} @@FIELD@@ {/if}',

Duh, the issue was the client had field level access plugin installed and the user profile I was using didn’t have access to this field!!!

@pstevens

I want to add two examples for customCode, how to use multiple fields in one block.

  1. Add an extension text field to multienum type.
  • vardef.php
...
'fields'=>array (
...
        'inspection' => array(
            'required' => '0',
            'name' => 'inspection',
            'vname' => 'LBL_INSPECTION',
            'type' => 'multienum',
            'massupdate' => 0,
            'comments' => '',
            'help' => '',
            'importable' => 'true',
            'duplicate_merge' => 'disabled',
            'duplicate_merge_dom_value' => 0,
            'audited' => 0,
            'reportable' => 0,
            'options' => 'bfhcav_inspection_list',
            'studio' => 'visible',
            'isMultiSelect' => true,
            'inline_edit'=>false,
        ),
        'inspection_ext' => array (
            'required' => false,
            'name' => 'inspection_ext',
            'vname' => 'LBL_INSPECTION_EXT',
            'type' => 'text',
            'massupdate' => 0,
            'no_default' => false,
            'comments' => '',
            'help' => '',
            'importable' => 'true',
            'duplicate_merge' => 'disabled',
            'duplicate_merge_dom_value' => '0',
            'audited' => false,
            'reportable' => true,
            'unified_search' => false,
            'merge_filter' => 'disabled',
            'len' => '255',
            'size' => '20',
            'inline_edit' => false,
        ),
...
),
...
  • editviewdefs.php
...
1 => array (
                        'name' => 'inspection', 
                        'customCode' => '<span>
                                @@FIELD@@
                            </span>
                            <span style="display:inline-block;width:100%;margin:5px;">
                                <span class="label" style="margin:5px;line-height:10px;float:left">{$MOD.LBL_INSPECTION_EXT}</span>
                                <textarea name="inspection_ext" id="inspection_ext" rows="3" cols="80" title="" tabindex="0" value="">{$fields.inspection_ext.value}</textarea>
                            </span>',
                    ),
...
  • detailviewdefs.php
...
1 => array (
                        'name' => 'inspection', 
                        'label' => 'LBL_INSPECTION_DETAILVIEW',
                        'customCode' => '
                            {multienum_to_array string=$fields.inspection.value assign="vals"}
                            {foreach from=$vals item=item}
                                <li style="margin-left:10px;line-height:1.428571429;" value="$item">{ $APP_LIST_STRINGS.bfhcav_inspection_list.$item }</li>
                            {/foreach}
                            <span style="display:inline-block;width:100%;margin:5px;">
                                <span name="inspection_ext" id="inspection_ext">{$fields.inspection_ext.value}</span>
                            </span>',
                    ),
...

  1. This is a table with boolean fields.
  • vardefs.php
...
'fields'=>array (
...
// two of eight fields
        'office_existence'=>array(
            'required' => false,
            'name' => 'office_existence',
            'vname' => 'LBL_OFFISE_EXISTENCE',
            'type' => 'bool',
            'massupdate' => 0,
            'default' => '0',
            'no_default' => false,
            'comments' => 'Office',
            'help' => '',
            'importable' => true,
            'duplicate_merge' => 'disabled',
            'duplicate_merge_dom_value' => '0',
            'audited' => false,
            'reportable' => true,
            'unified_search' => false,
            'merge_filter' => 'disabled',
            'inline_edit' => false,
        ),
        'office_designation'=>array(
            'required' => false,
            'name' => 'office_designation',
            'vname' => 'LBL_OFFISE_DESIGNATION',
            'type' => 'bool',
            'massupdate' => 0,
            'default' => '0',
            'no_default' => false,
            'comments' => 'Office',
            'help' => '',
            'importable' => true,
            'duplicate_merge' => 'disabled',
            'duplicate_merge_dom_value' => '0',
            'audited' => false,
            'reportable' => true,
            'unified_search' => false,
            'merge_filter' => 'disabled',
            'inline_edit' => false,
        ),
// add other fields here
...
),
  • editviewdefs.php
...
1 => array (
                        'name' => 'rooms', // 12.
                        'label' => 'LBL_ROOMS',
                        'customCode' => '
                            <table style="width:100%;text-align: center;">
                                <colgroup>
                                    <col span="1" style="width:40%;padding: 2px 5px;"></col>
                                    <col span="2" style="width:30%;padding: 2px 5px;"></col>
                                </colgroup>
                                <thead>
                                    <tr>
                                        <td><span></span></td>
                                        <td><span>{$MOD.LBL_YES}</span></td>
                                        <td><span>{$MOD.LBL_NO}</span></td>
                                    </tr>
                                </thead>
                                </tbody>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #A5E8D6;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_OFFICE}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="office_existence" value="0"> 
                                                <input type="checkbox" id="office_existence" name="office_existence" value="1" {if ($fields.office_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="office_designation" value="0"> 
                                                <input type="checkbox" id="office_designation" name="office_designation" value="1" {if ($fields.office_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #A5E8D6;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_SECRETARIAT}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="secretariat_existence" value="0"> 
                                                <input type="checkbox" id="secretariat_existence" name="secretariat_existence" value="1" {if ($fields.secretariat_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="secretariat_designation" value="0"> 
                                                <input type="checkbox" id="secretariat_designation" name="secretariat_designation" value="1" {if ($fields.secretariat_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #A5E8D6;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_PHOTOCOPY}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="photocopy_existence" value="0"> 
                                                <input type="checkbox" id="photocopy_existence" name="photocopy_existence" value="1" {if ($fields.photocopy_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="photocopy_designation" value="0"> 
                                                <input type="checkbox" id="photocopy_designation" name="photocopy_designation" value="1" {if ($fields.photocopy_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #A5E8D6;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_BAILIFFS}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="bailiffs_existence" value="0"> 
                                                <input type="checkbox" id="bailiffs_existence" name="bailiffs_existence" value="1" {if ($fields.bailiffs_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="bailiffs_designation" value="0"> 
                                                <input type="checkbox" id="bailiffs_designation" name="bailiffs_designation" value="1" {if ($fields.bailiffs_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #A5E8D6;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_TOILETS}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="toilets_existence" value="0"> 
                                                <input type="checkbox" id="toilets_existence" name="toilets_existence" value="1" {if ($fields.toilets_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="hidden" name="toilets_designation" value="0"> 
                                                <input type="checkbox" id="toilets_designation" name="toilets_designation" value="1" {if ($fields.toilets_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>',
                    ),
...
  • detailviewdefs.php
...
1 => array (
                        'name' => 'rooms', // 12.
                        'label' => 'LBL_ROOMS',
                        'customCode' => '
                            <table style="width:100%;text-align: center;">
                                <colgroup>
                                    <col span="1" style="width:40%;padding: 2px 5px;"></col>
                                    <col span="2" style="width:30%;padding: 2px 5px;"></col>
                                </colgroup>
                                <thead>
                                    <tr>
                                        <td><span></span></td>
                                        <td><span>{$MOD.LBL_YES}</span></td>
                                        <td><span>{$MOD.LBL_NO}</span></td>
                                    </tr>
                                </thead>
                                </tbody>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #FFFFFF;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_OFFICE}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="office_existence" name="office_existence" disabled="true" {if ($fields.office_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="office_designation" name="office_designation" disabled="true" {if ($fields.office_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #FFFFFF;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_SECRETARIAT}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="secretariat_existence" name="secretariat_existence" disabled="true" {if ($fields.secretariat_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="secretariat_designation" name="secretariat_designation" disabled="true" {if ($fields.secretariat_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #FFFFFF;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_PHOTOCOPY}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="photocopy_existence" name="photocopy_existence" disabled="true" {if ($fields.photocopy_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="photocopy_designation" name="photocopy_designation" disabled="true" {if ($fields.photocopy_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #FFFFFF;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_BAILIFFS}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="bailiffs_existence" name="bailiffs_existence" disabled="true" {if ($fields.bailiffs_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="bailiffs_designation" name="bailiffs_designation" disabled="true" {if ($fields.bailiffs_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr style="border-top-style: dashed;border-top-width: 1px;border-top-color: #FFFFFF;">
                                        <td style="padding-bottom:5px;">
                                            <span>{$MOD.LBL_TOILETS}</span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="toilets_existence" name="toilets_existence" disabled="true" {if ($fields.toilets_existence.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                        <td>
                                            <span style="display:inline-block;margin-left: 10px;">
                                                <input type="checkbox" id="toilets_designation" name="toilets_designation" disabled="true" {if ($fields.toilets_designation.value)}checked="checked"{else}{/if}>
                                            </span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>',
                    ),
...

1 Like

Thank you so much @p.konetskiy these are great examples! I’ve been using this feature alot lately and have read all your previous posts and comments on this subject. They are great!

I’ll have to try your foreach syntax! I was trying to get that to work for a dropdown for hours. I eventually gave up and passed the value like this by extending the viewedit with the display function:

 // Pass app_list_strings to Smarty template
        $this->ev->ss->assign('APP_LIST', $app_list_strings);

And then in the custom code like this:

'customCode' => '{if $isAdministrator}
		  @@FIELD@@
		  {elseif $fields.sales_stage.value eq "Closed Won" || $fields.sales_stage.value eq "Closed Lost"}
		          <span>{$APP_LIST.sales_stage_dom[$fields.sales_stage.value]}</span>
		  {else}
		  @@FIELD@@
		  {/if}',

A foreach loop is simpler, I can’t wait to try.

1 Like