1
votes

I am net to Timber and TWIG. I can't get the dynamic sidebar to show up. My goal is for the content to only show up if there is a dynamic sidebar and you are on the front-page.php. Currently it tells me that there is widget area, however I am not on the correct page. I am sure that front-page.php is getting rendered however. I am working with the Timber starter theme (Github) for Wordpress as a base. I can get the Widgets to show, if I add the code directly which I commented out in the front-page.twig

sidebar.php

#Timber::render( array( 'sidebar.twig' ), $data ); if i understand right, i can remove this?

$context = array();
$context['dynamic_sidebar'] = Timber::get_widgets('home_sidebar');
Timber::render('sidebar.twig', $context);

functions.php i added this to the end of the file:

function custom_widgets_init() {

    register_sidebar( array(
        'id'          => 'home_sidebar',
        'name'        => __( 'Dynamic Sidebar 1', $text_domain ),
        'description' => __( 'This sidebar is located on the left side of the content.', $text_domain ),
    ) );
}
add_action( 'widgets_init', 'custom_widgets_init' );

font-page.twig

{% extends "base.twig" %}

{# STUFF #}

{% block sidebar_area %}

        <aside>
            {{dynamic_sidebar}}
            {# {% do function('dynamic_sidebar', 'dynamic-sidebar-1') %} THIS HOWEVER WORKS #}
        </aside>

{% endblock %}

sidebar.twig : is currently empty

1
I have the feeling that I should actually add the content from my sidebar.php to front-page.php which currently doesn't exist. Will test this once I am back home. - Frizzant
That didn't do anything. - Frizzant

1 Answers

1
votes

@frizzant: if you haven't already check out the guide we put together for sidebars:

https://timber.github.io/docs/guides/sidebars/