ContentBlocks cropper in field and layout settings

Hi all,

I posted this question on the MODX forum a while back, to no avail unfortunately.

Hi everyone,

I’ve been working with MODX and the ContentBlocks extra for a while now. We frequently use the built-in cropper for image fields, and rely on Image+ when cropping is needed for template variables.

However, I’ve noticed that it’s not possible to use the cropper when adding a setting of the image field type to a layout or a field.

I’ve searched both Google and this forum but haven’t come across any relevant information. Has anyone else run into this or found a workaround?

Thanks!

I would like to use a cropper in a field or lay-out setting, but unfortunately this isn’t included out of the box, while it can be enabled for the image input type.

Does anyone have a solution for this or can someone point me in the right direction?

Thanks!

Hello Thomas,
maybe late, but anyway: AFAIK this is really not possible. But you can try some workarounds, not elegant as native feature, but working.

We almost everywhere in MODX template use our custom output filter to content field (like [[*content:contentFilter]] that cleans up and modify code, doing some smart stuff that’s not possible with CB (e.g. responsive tables from standard TinyMCE tables, interactive tabs from CB repeater etc). This “contentFilter” uses PHP simple HTML DOM parser (PHP Simple HTML DOM Parser download | SourceForge.net) to manipulate content field (rich text or generated from CB).

You can create layout that needs cropped image, but leave param for that image empty (whatever it is, maybe inline css backgroud image). Like

<section class="my-layout" style="">
[[+main]]
</section>

Then you create special field of type Image, available only in that layout. Template for that field is not necessarily img tag, but it doesn’t matter
<img class="layout-image" data-src="[[+crops.free.url]]">

To make it simple for user, create CB template combining layout and image field.

Then in contentFilter snippet, it’s something like this (sorry, not tested, need tweaking):

<?php
require_once MODX_BASE_PATH . '_custom/php/simple_html_dom.php';
$html = new simple_html_dom;
$html->load($input, true);
foreach($html->find('.my-layout') as $l){
 $img = $l->find('.layout-image',0);
 $src = $img->src;
 $img->outertext = ''; //remove helper img from DOM
 $l->style = 'backgroud-image: url(' . $src . ');'; //inject image into parent layout
}
return $html;

All this is cached, so don’t worrky about speed. Hope this helps.