Add div with background image?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: April 19, 2017   (RSS)

By Toledoh - April 19, 2017

Hey All.

I need to have a CMSB user be able to add an image via WYSIWYG, but have it generate

<div class="cyclotron" style="background:url(panorama.jpg);height:512px"></div>

I was thinking of possibly adding the image as normal, then giving it a class of "cyclotron", so it would be like

<img class="cyclotron" src="url(panorama.jpg)" />

Then having some kind of string_replace?

Any ideas?

Cheers,

Tim (toledoh.com.au)

By Toledoh - April 19, 2017

Yeah, has to be via wysiwyg so they can place the content where they like on the page, and have multiple per text field. 

Cheers,

Tim (toledoh.com.au)

By Toledoh - April 19, 2017

Would something like this work?

<?php
$str = '<img class="cyclotron" src="url(panorama.jpg)" />';

$str = preg_replace('<img class="cyclotron" src="url(.*?)" />', 'div class="cyclotron" style="background:url($1);height:512px"></div', $str);

echo $str;


?>

But I also expect that if this does in fact work, it would only work for a single occurrence?

Cheers,

Tim (toledoh.com.au)