I am using Timber to create a very basic WordPress theme.
I’m stuck though.
I want to create Widget areas in the theme and I can’t figure it out.
I’ve tried following the instructions, for creating a Dynamic Widget, on this page – https://github.com/jarednova/timber/wiki/Sidebar#method-3-dynamic
By following this I’ve added the following code to my files –
To page-frontpage.php I added
$context['dynamic_sidebar'] = Timber::get_widgets('dynamic_sidebar');
so it now looks like this:
<?php
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$context['dynamic_sidebar'] = Timber::get_widgets('dynamic_sidebar');
Timber::render(array('page-' . $post->post_name . '.twig', 'page.twig'), $context);
I then added this to the base.twig file
<section>
{{ dynamic_sidebar }}
</section>
I expected to see a new Widget area in the WordPress Admin under Appearance -> Customize but got nothing.
I’ve struggled with this for the past few hours and made little progress, any help would be greatly appreciated.
Thank you.
I’ve fixed this issue.
I just had to go back to basics and create the widgets in the functions.php file, so now my code looks something like this.
in functions.php
in page-home.php
in home.twig
Hope this helps someone in the future