Creating a Widget area in my Wordpress Timber Theme

John Behan

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.

John Behan

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

register_sidebar( array(
            'name' => 'Home left sidebar',
            'id' => 'home_left',
            'before_widget' => '<div>',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="rounded">',
            'after_title' => '</h2>',
        ) );

in page-home.php

$context['home_left'] = Timber::get_widgets('home_left');

in home.twig

<div class="left-box">{{ home_left }}</div>

Hope this helps someone in the future

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Customizing Theme My Login widget on wordpress

From Dev

Creating a wordpress theme

From Dev

Adding Widget to Wordpress Genesis Theme

From Dev

My wordpress theme error

From Dev

Creating an octopress theme from a wordpress theme

From Dev

Creating an octopress theme from a wordpress theme

From Dev

Widget Area disappeared under Appearance -> Widget Wordpress

From Dev

How can I specify that an area of my custom WordPress theme have to contains widgets\modules?

From Dev

Creating a night theme for my app

From Dev

characters issue with my wordpress theme

From Dev

characters issue with my wordpress theme

From Dev

How to register a widget in WordPress Genesis child theme?

From Dev

WordPress theme creation : There are no widget areas on the page shown

From Dev

WordPress: Adding a widget area to the primary page template?

From Dev

One widget area for footer instead of 3? [wordpress]

From Dev

Confusion of creating a child theme properly in wordpress

From Dev

Getting jQuery to load when creating a Wordpress theme

From Dev

Using theme for my Qt widget application

From Dev

Wordpress: Add html code to widget area without using a text widget

From Dev

Creating widget like WordPress in custom cms

From Dev

Wordpress Theme Customizer - Add area for users to move around and organize widgets

From Dev

My first child theme wordpress - color issue

From Java

Best way to define constants in my Wordpress theme

From Dev

Pushing updates to my premium WordPress theme

From Dev

Escaping untrusted data in php for my wordPress theme

From Dev

My Wordpress, Bootstrap theme is not working with JavaScript

From Dev

WordPress My theme options settings not saving

From Dev

Should I modify my Wordpress theme by myself?

From Dev

My first child theme wordpress - color issue

Related Related

  1. 1

    Customizing Theme My Login widget on wordpress

  2. 2

    Creating a wordpress theme

  3. 3

    Adding Widget to Wordpress Genesis Theme

  4. 4

    My wordpress theme error

  5. 5

    Creating an octopress theme from a wordpress theme

  6. 6

    Creating an octopress theme from a wordpress theme

  7. 7

    Widget Area disappeared under Appearance -> Widget Wordpress

  8. 8

    How can I specify that an area of my custom WordPress theme have to contains widgets\modules?

  9. 9

    Creating a night theme for my app

  10. 10

    characters issue with my wordpress theme

  11. 11

    characters issue with my wordpress theme

  12. 12

    How to register a widget in WordPress Genesis child theme?

  13. 13

    WordPress theme creation : There are no widget areas on the page shown

  14. 14

    WordPress: Adding a widget area to the primary page template?

  15. 15

    One widget area for footer instead of 3? [wordpress]

  16. 16

    Confusion of creating a child theme properly in wordpress

  17. 17

    Getting jQuery to load when creating a Wordpress theme

  18. 18

    Using theme for my Qt widget application

  19. 19

    Wordpress: Add html code to widget area without using a text widget

  20. 20

    Creating widget like WordPress in custom cms

  21. 21

    Wordpress Theme Customizer - Add area for users to move around and organize widgets

  22. 22

    My first child theme wordpress - color issue

  23. 23

    Best way to define constants in my Wordpress theme

  24. 24

    Pushing updates to my premium WordPress theme

  25. 25

    Escaping untrusted data in php for my wordPress theme

  26. 26

    My Wordpress, Bootstrap theme is not working with JavaScript

  27. 27

    WordPress My theme options settings not saving

  28. 28

    Should I modify my Wordpress theme by myself?

  29. 29

    My first child theme wordpress - color issue

HotTag

Archive