[WP] Adding your custom {{variables}} to Slide Markup Editor

This tutorial requires PHP knowledge!

Since version 3.0.4 there is WordPress filter new_rs_slides_renderer_helper that allows adding custom Mustache helpers.

Example that will add variables {{hello_world}} variable to Slide Markup Editor:

function newrs_add_custom_variables($m, $data, $options) {
    $m->addHelper('hello_world', function() {
           return 'Hello world!';
    } );
add_filter('new_rs_slides_renderer_helper', 'newrs_add_custom_variables', 10, 4);

More info about syntax in mustace.php documentation.

Example, get ACF field value for "Posts" slider:

Code below will create variable, called {{test_variable}}, which will return value of custom field with
field-name test. ACF get_field documentation http://www.advancedcustomfields.com/resources/get_field/

function newrs_add_acf_variable($m, $data, $options) {
    $m->addHelper('test_variable', function() use ($data) {

           // $data is a WordPress post object (for posts-slider)

           // just return value
           return get_field( "test", $data->ID ) ;
    } );

add_filter('new_rs_slides_renderer_helper','newrs_add_acf_variable', 10, 4);

Example, get ALT attribute of image in "Custom" slider

Creates {{alt_text_custom}} variable that returns alt field of media library image object.

function newrs_add_custom_alt_variable($m, $data, $options) {
    $m->addHelper('alt_text_custom', function() use ($data) {
        // $data object holds all data about slide
        // print_r($data);
        if(isset($data['image']) && isset($data['image']['attachment_id'])) {
            $attachment_id = $data['image']['attachment_id'];
            return get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
         return '';
    } );     
add_filter('new_rs_slides_renderer_helper','newrs_add_custom_alt_variable', 10, 4);