You are not logged in.
Pages: 1
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
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
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
The only way at the moment is to use the Image List or Grouped Image List view types.
Offline
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
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
Pages: 1