Hi!!
So far I have only worked with repeater and everything was fine. But in the widget that I’m creating, I have a repeater inside another repeater and I can’t show the content on my website.
To be able to call the elements in the template, I write this function
function get_template_variables($instance) {
$vars = [];
$vars[‘items’] = $instance[‘section_items’][‘items’];
return $vars;
}
And in my template, I call them like this:
But in this case, since it is a repeater inside another, it does not show them to me. Do you have an example created?
Sorry, I forgot to add this
I think you have a bug when we try to create a repeater inside another repeater.
I have tried another option. I have tried to include widget within a repiter, but when the widget that I use has a repeater inside, it doesn’t work. If it doesn’t have repeater, it works fine.
Hi Laguillen,
Can you please provide me with a copy of your complete widget code so I can take a look over it?
The SiteOrigin Hero widget has two repeaters within the main repeater – the background video and Button (which is the complete button widget). You can find its code here.
Finally, the widget in the second repeater is already displayed on the back.
I have seen the example of the hero, but it is quite messy, especially because it contains many functions that I do not know exactly what they do.
What I would miss now, is to display in the template.php the items that are in the widget that I have included in the second repeater.
If I do a “”var_dump” of my widget, the data that brings me are these:
array(1) { [0]=> array(1) { [“button”]=> array(2) { [“section_bg”]=> array(5) { [“image_url”]=> int(616) [“image_url_fallback”]=> string(0) “” [“so_field_container_state”]=> string(4) “open” [“bg_type”]=> string(5) “image” [“veil”]=> bool(false) } [“section_text”]=> array(2) { [“claim”]=> string(15) “TEXTO DE PRUEBA” [“so_field_container_state”]=> string(4) “open” } } } }
What I need is to know how to show this data in my template.
<?php I will try to paste it again with the spaced /* Widget Name: Tabla Tarifas TLM Description: abla Tarifas TLM Author: Flying Pigs Author URI: http://flyingpigs.es */ class Table_Widget extends SiteOrigin_Widget { function __construct() { //Here you can do any preparation required before calling the parent constructor, such as including additional files or initializing variables. //Call the parent constructor with the required arguments. parent::__construct ( // The unique id for your widget. 'tlm-tablas-widget', // The name of the widget for display purposes. 'Tablas-Tarifas TLM', // The $widget_options array, which is passed through to WP_Widget. // It has a couple of extras like the optional help URL, which should link to your sites help or support page. array( 'description' => 'Tabs-Slider TLM - Módulo de contenido', 'panels_groups' => array('fp-widgets'), 'panels_icon' => 'dashicons dashicons-admin-page' ), //The $control_options array, which is passed through to WP_Widget array( ), //The $form_options array, which describes the form fields used to configure SiteOrigin widgets. array( 'section_items' => array( 'type' => 'section', 'label' => 'Tabla Tarifas', 'hide' => false, 'fields' => array( 'table_title' => array( 'type' => 'text', 'label' => 'TÃtular del bloque', 'default' => '', 'optional' => true ), 'items' => array( 'type' => 'repeater', 'label' => 'Elementos del módulo', 'item_name' => 'Elemento', 'item_label' => array( 'selector' => "[id*='icon_title']", 'update_event' => 'change', 'value_method' => 'val' ), 'fields' => array( 'tab_title' => array( 'type' => 'text', 'label' => 'TÃtular del tab', 'default' => '', 'optional' => true ), 'th_one' => array( 'type' => 'text', 'label' => 'TÃtulo columna uno', 'default' => '', 'optional' => true ), 'th_two' => array( 'type' => 'text', 'label' => 'TÃtulo columna dos', 'default' => '', 'optional' => true ), 'th_three' => array( 'type' => 'text', 'label' => 'TÃtulo columna tres', 'default' => '', 'optional' => true ), 'th_four' => array( 'type' => 'text', 'label' => 'TÃtulo columna cuatro', 'default' => '', 'optional' => true ), 'buttons' => array( 'type' => 'repeater', 'label' => __('Crear nueva fila'), 'item_name' => __('Fila'), 'item_label' => array( 'selector' => "[id*='buttons-button-text']", 'update_event' => 'change', 'value_method' => 'val' ), 'fields' => array( 'button' => array( 'type' => 'widget', 'label' => __( 'Button Widget', 'tlm-claim-small-widget' ), 'class' => 'Claim_Small_Widget', 'collapsible' => false, ) ) ), 'table_info' => array( 'type' => 'textarea', 'label' => 'Info adicional', 'default' => '', 'rows' => 5, 'optional' => true ), 'table_link_text' => array( 'type' => 'text', 'label' => 'Texto del enlace', 'default' => '', 'optional' => true, 'state_handler' => array( 'item_link_type_{$repeater}[none]' => array('hide'), '_else[item_link_type_{$repeater}]' => array('show') ) ), 'table_link_url' => array( 'type' => 'link', 'label' => 'Url del enlace', 'default' => '', 'optional' => true, 'sanitize' => 'url', 'state_handler' => array( 'item_link_type_{$repeater}[link]' => array('show'), '_else[item_link_type_{$repeater}]' => array('hide') ) ), 'table_link_new_window' => array( 'type' => 'checkbox', 'default' => false, 'label' => 'Abrir enlace en pestaña nueva', 'state_handler' => array( 'add_link[none]' => array('hide'), 'add_link[yes]' => array('show') ), ), ) ) ) ) ), //The $base_folder path string. plugin_dir_path(__FILE__) ); } function initialize() { $this->register_frontend_scripts( array( array( 'tlm-tablas-widget', plugin_dir_url( __FILE__ ) . 'js/tlm-tablas-widget-scripts.js', array( 'jquery' ), '1.0' ) ) ); } function get_template_variables($instance) { $vars = []; //$vars['tab_image'] = ''; $vars['items'] = $instance['section_items']['items']; return $vars; } function get_template_name($instance) { return 'tlm-tablas-widget-template'; } function get_style_name($instance) { return 'tlm-tablas-widget-style'; } } siteorigin_widget_register('tlm-tablas-widget', __FILE__, 'Table_Widget');<div class="fp_table-tlm"> <div class="container"> <h2 class="h2"> <?php echo $items[$j]['table_title']; ?> </h2> <div class="inner wrapper-tabs"> <div class="container-nav-tabs"> <ul class="nav nav-tabs" role="tablist"> <?php for ($j = 0; $j < count($items); $j++): ?> <li class="nav-item"> <a class="nav-link <?php if ($j == 0) { ?>active<?php } ?>" href="#<?php echo $j;?>" aria-controls="<?php echo $j;?>" role="tab" data-toggle="tab" aria-controls="<?php echo $j;?>" aria-selected="<?php if (j == 0) {?> true <?php } else { ?> false <?php } ?>"> <?php if($items[$j]['tab_title'] != ''): ?> <?php echo $items[$j]['tab_title']; ?> <?php endif; ?> </a> </li> <?php endfor; ?> </ul> </div> <!-- Tab panes --> <div class="tab-content"> <?php for ($i = 0; $i < count($items); $i++): ?> <div role="tabpanel" class="tab-pane <?php if ($i == 0) { ?>active show<?php } ?>" id="<?php echo $i;?>"> <div class="item"> <table class="table"> <thead> <tr> <th scope="col"><?php echo $items[$i]['th_one']; ?></th> <th scope="col"><?php echo $items[$i]['th_two']; ?></th> <th scope="col"><?php echo $items[$i]['th_three']; ?></th> <th scope="col"><?php echo $items[$i]['th_four']; ?></th> </tr> </thead> <tbody> <tr> <th scope="row"><?php echo $fila['td_one'] ?></th> <td><?php echo $fila[$i]['td_two']; ?></td> <td><?php echo $fila[$i]['td_trhee']; ?></td> <td><?php echo $fila[$i]['td_four']; ?></td> </tr> </tbody> </table> <?php if($items[$i]['table_link_url'] != ''): ?> <a href="<?php echo sow_esc_url($items[$i]['table_link_url']); ?>" class="btn-tlm btn-white" <?php if($items[$i]['table_link_new_window']): ?> target="_blank" <?php endif; ?>> <?php echo $items[$i]['table_link_text']; ?> </a> <?php endif; ?> <?php var_dump($items[$i]['buttons']); ?> </div> </div> <?php endfor; ?> </div> </div> <!-- Bootstrap Accordion --> <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"></div> </div> </div>Hi Laguillen,
You’ll need to iterate the repeater array. The template code you included in your reply assumes that we do this automatically which isn’t the case as not all widgets use repeater fields. You’ll need to set up the loop manually.