Custom List Column types

In a plugin's backend you can have models that show a grid of records to maintain tables.

In this sample I want to get country details from a selected country from the Rainlab/Location plugin.


In the columns YAML in plugins/yournamespace/yourplugin/models/yourtable/columns.yaml:

    ... here you have your own specs ...
        type: country_details
        relation: country
        invisible: true
        path: ~/plugins/yournamespace/yourplugin/partials/columns/_country_flag.htm
    ... more specs ...    


The new type is _countrydetails and will be defined in the Plugin.php.

In the Plugin.php:

use Rainlab\Location\Models\Country;
use Yournamespace\Yourplugin\Controllers\Yourcontroller as PluginController;

public function registerListColumnTypes()
        return [
            'country_details' => [$this, 'evalCountryDetailsListColumn'],


  * $value = field value, this is the value for the 'country_id:' in the YAML
  * if the 'xxx:' field in the YAML doesn't exist in a model, this value will
  * be null.
  * $colum = column definition
  * $record = model (record)
public function evalCountryDetailsListColumn($value, $column, $record)
   $country = Country::where('id', $record->country_id)->first();

   $controller = new PluginController();

   $partial = $controller->makePartial($column->path, [
       'value' => $value,
       'column' => $column,
       'record' => $record,
       'country' => $country

   return $partial;



Partial: ~/plugins/yournamespace/yourplugin/partials/columns/_country_flag.htm

if ($country) {
   printf('<img src="$s/flat/32.png">&nbsp;%2$s',


Last update: Tue, 13 Sep 2022 14:32:15