WYSIWYG field > multiple divs > carousel

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 17, 2015   (RSS)

By Toledoh - June 16, 2015

Hi All.

I have a field which can end up being a large amount of text.  To keep the style of the site, I want to break this long text into chucks and wrap each chunk in a div, then display those divs in a carousel.

So, I'm thinking that somehow I could convert a single field into an array - maybe based on X number of characters of text?  Then create a for-each loop for each div? From there I can handle the display...

Can anyone help with this?

Cheers,

Tim (toledoh.com.au)

By Dave - June 17, 2015

Can you have the source text be a textbox?  It's much easier with text:

$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id
vestibulum leo. Proin non condimentum libero. Vestibulum iaculis consectetur
purus lobortis tristique. Sed malesuada aliquet nibh. Aliquam erat volutpat.
Aliquam erat volutpat. Integer convallis sapien sed sem lacinia, at malesuada
metus consectetur. Vestibulum eget varius diam. Cras aliquet nec nibh quis
lacinia. Aenean tempus auctor lacinia. Fusce placerat, sapien quis condimentum
varius, nunc nulla pharetra lorem, non tristique tortor lectus vel risus. Aenean
malesuada sem id nulla sodales sagittis.";

$textWithTabs = wordwrap($text, 150, "\t");
$textChunkArray = explode("\t", $textWithTabs);
showme($textChunkArray);
exit;

Outputs: 

Array
(
    [0] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id 
vestibulum leo. Proin non condimentum libero. Vestibulum iaculis consectetur 
purus
    [1] => lobortis tristique. Sed malesuada aliquet nibh. Aliquam erat volutpat. 
Aliquam erat volutpat. Integer convallis sapien sed sem lacinia, at malesuada
    [2] => 
metus consectetur. Vestibulum eget varius diam. Cras aliquet nec nibh quis 
lacinia. Aenean tempus auctor lacinia. Fusce placerat, sapien quis
    [3] => condimentum 
varius, nunc nulla pharetra lorem, non tristique tortor lectus vel risus. Aenean 
malesuada sem id nulla sodales sagittis.
)

With HTML you need to match the tags and make sure you close them, and don't split in the middle of a tag, etc.  Possible, but fair bit trickier.

Let me know if the above works for you.

Dave Edis - Senior Developer
interactivetools.com