Best way to extend .tpl file for a custom ListView?

I have a custom listview and I wanted to customize the .tpl file for it.

in listViewProcess() method the default tpl is loaded via:
$this->lv->setup($this->seed, ‘include/ListView/ListViewGeneric.tpl’, $this->where, $this->params);

So I copied the above and pointed to a new .tpl file

$this->lv->setup($this->seed, ‘include/ListView/ListViewShowStorage.tpl’, $this->where, $this->params);

The new .tpl file is in the same folder. But the template looks off… The arrows do not appear because for some reason the markup is different, eventhough I copied the contents of ListViewGeneric.tpl to ListViewShowStorage.tpl

Am I doing something wrong?

I don’t think you should be editing it there. Apart from not being upgrade-safe, it is a place where many different screens will be affected, and I doubt that’s really what you want.

If probably could use instead, an override to the display class where you change the screen elements that you want to change only for that single view.

you’re right, i don’t even know why i assumed that that’s the file I’ll need to change. I wanted to change how the URLs are displayed inside a given list view.

Solution was to create a new bean in the custom/modules folder, extend the original bean class from the /modules folder and override the get_list_view_data() method

    require_once("modules/strg_storage/strg_storage.php");

    // Extend the original class found in the require_once()
    class strg_storage_c extends strg_storage //
    {

        function get_list_view_data(){

            // Get the default output
            $temp_array = parent::get_list_view_data();

            // Build up the custom link
            $temp_array['NAME']  =  '<a href=\'index.php';
            $temp_array['NAME'] .= '?module=strg_storage';
            $temp_array['NAME'] .= '&action=AssignstoragetoinventoryEdit';
            $temp_array['NAME'] .= '&return_module=strg_storage';
            $temp_array['NAME'] .= '&return_action=DetailView';
            $temp_array['NAME'] .= '&record='.$this->id;
            $temp_array['NAME'] .= '&inventory_unit_id='.$_REQUEST['un_inventory_id'];
            $temp_array['NAME'] .= '&storage_unit_id='.$this->id;
            $temp_array['NAME'] .= '\'>';
            $temp_array['NAME'] .= $this->name;
            $temp_array['NAME'] .= '</a>';

            return $temp_array;
        }


    }

Then I created a custom listview and then in controller.php I registered that custom listview (showprojectunitslis) and pointed to the custom bean class which overrides the get_list_view_data() when that view is fired up

Like so:


<?php

// The custom bean file that we created above
require_once("custom/modules/strg_storage/strg_storage_c.php");

class strg_storageController extends SugarController
{

    // If this custom action is called then instantiate our custom bean in /custom/modules/strg_storage/strg_storage_c.php so it can override how the URLs are displayed inside the custom listview
    public function action_showprojectunitslist() {

        // Register the custom action
        $this->view = 'showprojectunitslist';

        // Assign the custom bean
        $this->bean = new strg_storage_c();


    }

Anyways, yeah. Really didn’t need to extend the .tpl file

1 Like

That’s a nice solution, thanks for sharing! B-)