This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Farzin.b
Farzin.b

Hi guys I use user plugin, and i want show user image in the backend list, How can i do it? I know we should use partial, but i don't know what are codes in the partial? Please help me. I'm a beginner.

neilcarpenter
neilcarpenter

In your plugins plugin.php file use the Rainlab user model and Rainlab users controller

use Rainlab\User\Models\User;
use Rainlab\UserControllers\Users;

Extend the backend user model in your plugin.php boot method

public function boot()
{
    \Event::listen('backend.list.extendColumns', function($widget) {

        // only affect the rainlab users controller
        if (!$widget->getController() instanceof Users) {
            return;
        }

        // Only affect the backend user moder
        if (!$widget->model instanceof User) {
            return;
        }

        // add the column definition
        $widget->addColumns([
            'photo' => [
                'label' => 'Photo',
                'type' => 'partial',
                'path' => '~/plugins/author/my-plugin/views/partials/_backend_photo_column.htm'
            ]
        ]);
    });
}

Create a partial in that location, and in your _backend_photo_column.htm

<?php if (!is_null($record->avatar)): ?>
    <img src="<?=$record->avatar->getThumb(50, 50, 'crop'); ?>"/>
<?php endif; ?>

Last updated

neilcarpenter
neilcarpenter

Just realised you said you're using the User plugin - is that the Rainlab User plugin?

It's pretty much the same but use the Rainlab\User\Models\User; and Rainlab\User\Controller\Users; classes instead of the backend user model and controller and check for this in the boot. method instead...

I'll update the comment for this...

Last updated

mjauvin
mjauvin

Note: when giving paths to plugins files, you can use the $ prefix instead of using "~/plugins/"

i.e. "$/author/plugin/..."

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.