pepebe
3/10/2015 - 10:53 AM

Divide a placeholder delimited by a character into different placeholders.

Divide a placeholder delimited by a character into different placeholders.

<?php

/*
    Divide a placeholder delimited by a character into different placeholders.
    
    Usage:
    --------------------------------------------
    [[*pagetitle]] = My | Wonderful | Pagetitle
    
    [[*pagetitle:explode]]
    
    The default delimiter is "-", you can change this by passing an option to the snippet.
    [[*pagetitle:explode=`|`]]
    
    [[+pagetitle.count]] = 3
    
    [[+pagetitle.0]] = My
    [[+pagetitle.1]] = Wonderful
    [[+pagetitle.2]] = Pagetitle
    
*/

    $options = !empty($options) ? $options : '-';
    
    $count = count($options);
    $modx->setPlaceholder($name.'count', $count);

    $elements = explode($options, $input);
    foreach($elements as $key => $element){
        $modx->setPlaceholder($name.'.'.$key,trim($element));
    }
    return ' ';