Change status text in columns.yaml in OctoberCMS

- 1 answer

Ad

enter image description here

I Want to Change Yes/No to Active/Closed for that i have tried

status:
        label: Status
        type: group
        conditions: status in (:filtered)
        options:
            pending: Pending
            active: Active
            closed: Closed

AND

status:
        label: Status
        type: switch

The above code is found in https://octobercms.com/docs/backend/lists#column-switch

Can anyone have any solution ?

Ad

Answer

Ad

There is no yaml configuration for switch column type to do this, but two other solutions are possible

Method 1. You need to override localization file.

  • Create lang/en/backend directory in your project folder
  • Create file lang.php and add there:
 <?php    
   return [
       'list' => [
          'column_switch_true' => 'Active',
          'column_switch_false' => 'Closed'
       ],     
   ];
  • (optional) The base lang file is modules/backend/lang/en/lang.php if you have to override another messages

Downside:

  • It will affect ALL switch type columns

Method 2. Create partial for this column

  • Change yaml configuration for the column to:

    status: label: Status type: partial path: column_status

  • Add file _column_status.htm to the according folder in controllers folder with content:

<?php if($value) :?>
    Active
<?php else: ?>
    Closed
<?php  endif ?>
Ad
source: stackoverflow.com
Ad