#theme_wrappers doesn't wrap the #theme template

by Marwen Amri   Last Updated April 15, 2019 00:07 AM

I want to wrap the #theme template using a #theme_wrapper template :

 //Call the  registred theme
function _drupal7_test_fb_config_form(){
    $theme = [
        '#theme' => 'fb_users',
        '#theme_wrappers' => array('fb_users_wrapper'),
        '#item_1' => 'value of item 1',
        '#item_2' => 'value of item 2',
    ];
    return $theme;
}

the #theme is rendered correctly using 'theme_fb_users' ,and also the wrapper theme but $render_array['#children'] is empty? I have supposed that it will contain the #theme template html :

//#theme
function theme_fb_users($variables) {
    $render_array = $variables['render_array'];
    echo "<ul>";
        echo "<li>{$render_array['#item_1']}</li>";
        echo "<li>{$render_array['#item_2']}</li>";
    echo "</ul>";
}

//#theme_wrappers
function theme_fb_users_wrapper($variables) {
    $render_array = $variables['render_array'];
    //this doesn't wrap the #theme, bc $render_array['#children'] is empty
    echo "<div class='users_wrappers'>{$render_array['#children']}</div>";

}

//Defining themes
function  drupal7_test_theme($existing, $type, $theme, $path){
    $themes['fb_users'] =[
        'render element' => 'render_array'
    ];
    $themes['fb_users_wrapper'] =[
        'render element' => 'render_array'
    ];
    return $themes;
}
Tags : theming hooks


Related Questions


Updated July 19, 2016 08:03 AM

Updated June 04, 2015 22:03 PM

Updated March 02, 2017 13:07 PM

Updated March 07, 2017 19:07 PM

Updated April 30, 2017 09:07 AM