PHP code example of artygrand / shortcode

1. Go to this page and download the library: Download artygrand/shortcode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

artygrand / shortcode example snippets



r
//  '
[shortcode]
[short argument="value"]
[shortcode active other="complex value"]
[short]content[/short]
[shortcode argument="value"]content[/shortcode]

[span6]
    [span6]
        [span6   ]Lorem[/span6]
        [span4]
    [/span6]
    [span4]
        [span6 class="first" ]dolor[/span6]
        [col6  class="last" ]cudere[/col6]
    [/span4]
[/span6]

[span6]
    @[span6]
        [span6]Lorem[/span6]
    [/span6]
[/span6]
';

$sc = artygrand\Shortcode::getInstance();

$sc ->add('shortcode', 'func_shortcode')
    ->withAlias('short')

    ->add('span4', array(
        'grid',
        array('cols' => 4)
    ))

    ->add('span6', array(
        'grid',
        array('cols' => 6)
    ))
    ->withAlias('col6');

echo $sc->compile($sample);

// functions
function func_shortcode($args, $content = null){
    if (is_null($content)){
        return print_r($args, true);
    }
    $args['content'] = $content;
    return print_r($args, true);
}

function grid($args, $content = null){
    $args = array_merge(array(
        'cols' => 1,
        'class' => '',
    ), $args);

    $class = $args['class'] ? ' class="' . $args['class'] . '"' : '';

    if (is_null($content)){
        return '<div style="width:' . ($args['cols']/0.12) .'%;"' . $class . '>NoContent</div>';
    }
    return '<div style="width:' . ($args['cols']/0.12) .'%;"' . $class . '>' . $content . '</div>';
}