Forum

Thread tagged as: Problem, Gallery

Display Images with PerchAdminListing add_col method

When returning an image with $Listing->add_col([]); html like

<img src=""/>

is formatted to :

&lt;img src=""/&gt;

How can i output the html raw so it display the image, or can you use add_col to display a image in the admin another way?

Benjamin Verkleij

Benjamin Verkleij 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us what you're doing?

I'm creating a table of data:

$Listing = new PerchAdminListing($CurrentUser, $HTML, $Lang, $Paging);

Which works fine, but one column needs to be a thumbnail:

$Listing->add_col([
                'title'     => 'Thumb',
                'value'     => 'thumb',
            ]);

The 'thumb' value for example is '<img src="/images/my-image.jpg"/>' but that content gets run through PerchUtil.class.php with the html() method, as a string it's processed by

return htmlspecialchars($s, $q, 'UTF-8', $double_encode);

So basically i want to show an image in a table in the admin, but the value gets encoded before being displayed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

value call be a callable that returns whatever code you need.

'value' => function($item) {
    return '<img ...';
},

Hi Drew,

Is there a way to use a database result column value in the callable, normally for example if you look at perch_gallery:

$Listing->add_col([
                'title'     => $Lang->get('Slug'),
                'value'     => 'albumSlug',
                'sort'      => 'albumSlug',
            ]);

the value from 'albumSlug' is from the database results, but can you pass that result into your callable, as in;

$Listing->add_col([
                'title'     => $Lang->get('Slug'),
                'value'     => function($albumSlug) {
return '<img ...';
},
                'sort'      => 'albumSlug',
            ]);
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll be passed the entire album

'value' => function($album) { 
    return '<img ...' . $album->albumSlug(); 
},

Exactly what i was looking for, awesome, thanks!