#1 February 24, 2015 2:00pm

pier
Member
Registered: February 12, 2015
Posts: 17

Viewing crops in list views using parser

I'm trying to use a parser to display a cropped thumbnail in a list view.

I've tried different things but I'm not able to get an image in the list.

This echoes some "evaled" and trimmed text with an ellipsis

$url = $value;
$value = '<img src='.$url.'>';

This does the trick, but the URL of the image is wrong: {staticroot}files/modules/fileName.jpg
Even if I got the right URL I'd get the big image and not the crop.

$url = $value;
echo '<img src='.$url.'>';
$value = '';

So how can I access the crop of the upload field and display it in a list view?

Last edited by pier (February 24, 2015 2:10pm)

Offline

#2 February 24, 2015 3:50pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 978

Re: Viewing crops in list views using parser

A few different answers:

To get the cropped version, you'd generally want to use BigTree::prefixFile. This allows you to stick something like crop_ before the file name while preserving the full path. So if your crop of "test.jpg" was "crop_test.jpg" you'd call BigTree::prefixFile($url,"crop_").

To get the decoded path of an image (i.e. not {staticroot}), you need to use $cms->replaceRelativeRoots($value). I'm a bit torn as to whether the data your parser receives should already have roots decoded or not, but for now you get the raw data in parsers!

Echoing in a parser is only going to run when the view data is first cached (so when updating / creating a record and after modifying the view).

Cached view data is run through htmlspecialchars so putting images into a view is currently impossible. It's a strong possibility that this will work in BigTree 4.3 -- it's completely understandable that a developer may want to place HTML into the views explicitly through a view parser. Right now it's safer to sanitize all the data through htmlspecialchars than to allow malicious user data to make it into a view and expose the admin to a cross site scripting attack.

Offline

#3 February 24, 2015 7:03pm

pier
Member
Registered: February 12, 2015
Posts: 17

Re: Viewing crops in list views using parser

Thanks, you are super helpful Tim as always.

Isn't there any other way to display a thumb or crop in the list view?

Offline

#4 February 25, 2015 11:20am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 978

Re: Viewing crops in list views using parser

The only way at the moment is to use the Image List or Grouped Image List view types.

Offline

#5 December 8, 2016 9:40pm

mbriney
Member
From: Arlington, VA
Registered: December 8, 2016
Posts: 2

Re: Viewing crops in list views using parser

Tim,

Is it possible to create your own custom view type?  We're looking for something that's a hybrid between these two, a searchable list with a small thumbnail preview. 

-Matt

Offline

#6 December 9, 2016 12:20pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 978

Re: Viewing crops in list views using parser

The only way right now to create your own view is to create a Module Action that isn't related to a view/form/report and then create a related file for the action's route in /custom/admin/modules/{module-route}/{action-route}.php

BigTree 4.3 is going to have the ability for people to create custom view types that can be packaged as an extension and re-used, but it's still a few months out at the earliest!

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.