Albus One
Albus One

Reputation: 191

OctoberCMS backend list value

Is there a way to replace list value from 1 to Yes in backend form/list?

Example Database table entries

id - auto_increment
title - varchar
date - date
time - time
text - text
public - INT (1)

Now i created list in Builder which looks like this

List

So how would i replace 1 with Yes?

Upvotes: 0

Views: 1510

Answers (3)

kanapka94
kanapka94

Reputation: 76

You can also add 'context' attribute in columns.yaml file.

public:
    label: Public
    context:
        1: Yes
        0: No

Upvotes: 1

There is no need for partial in this particular case. It can be easily done in Builder.

  1. Navigate to your plugin
  2. Select model
  3. Open list manager
  4. Change column type to Switch

Switch

It will display Yes/No for you automatically depending on column value (1/0)

Upvotes: 1

For this you need to create a partial for the column https://octobercms.com/docs/backend/lists#column-partial

Modify your myplugin/models/themodel/columns.yaml file for the public field

public:
    type: partial
    path: ~/plugins/yourname/myplugin/models/themodel/_content_column.htm

The content _content_column.htm file will be

<?php if ($record->public==1): ?>
 Yes
<?php else: ?>
No
<?php endif; ?>

or

<?php if ($value==1): ?>
 Yes
<?php else: ?>
No
<?php endif; ?>

$value is the default cell value, $record is the model used for the cell

Upvotes: 0

Related Questions