by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Halian Vilela
    @halian-vilela
    I'm having a very annoying issue with WPML and it's a pain to debug, I have no idea on what to do anymore...
    Sander Scheijbeler
    @sanderscheijbeler
    @halian-vilela , I cant help you with the details but i heard one of the devops guys in my company complain about the old / crappy code used by WPML. They are trying to rebuild the project to get it out of the way.
    Miles Blackwood Robinson
    @blackwood
    I know it's a mostly unused feature in WordPress with or without Timber, but does anyone know the best way to render bookmarks in a manner similar to wp_list_bookmarks? having a hell of a time getting get_bookmarks to predictably return category names and wondering if there isn't a Timber shortcut already
    Alex James Bishop
    @aj-adl
    Hey guys, I just thought I'd jump on here and ask a Q because it's not really an issue
    but how do you build the timber docs? I know we have the docs folder, with the MD files etc, bit I'm interested in reading / working on the docs for 2.0 as I can see there's a few open issues there, and just want to get a better understanding of where things are heading.
    I've submitted a few PR's recently, but it seems silly to keep plugging away at 1.9.x issues when 2.0 will be a big shift
    Alex James Bishop
    @aj-adl
    ah I just saw it's a different repo, my bad!
    saltymouse
    @saltymouse
    I have a rather basic question: I have a simple custom text field (ACF) linked to an "About" page. I pass this page's ID to Timber like so: $context['about'] = new Timber\PostQuery(8); and then from the corresponding twig template I can {{ about | print_r }} and indeed see the text I entered into that field. However, following the guide, I'm unable to output that specific text field {{ about.meta('my_custom_text') }}outputs nothing.
    I'm just wondering how to get the data from an ACF on a single page, then relay that to the twig templates.
    saltymouse
    @saltymouse

    OK, so I think I figured it out... by just setting the page-specific ACF fields to PHP variables, then passing those through the $context object, it seems Timber is able to render those.

    $about_text = get_field('about_text', 8);
    $context['about_text'] = $about_text;

    Then {{ about_text }} in twig.

    This is similar to plain PHP templating with ACF fields. I was just thinking there'd be some Timber magic that would obviate this clumsy setup using get_field all the time.

    saltymouse
    @saltymouse
    Seems like I should be able to use the meta() function though... very strange why it's not working...
    Alex James Bishop
    @aj-adl
    @saltymouse does about.my_custom_text or about.get_field('my_custom_text') work
    saltymouse
    @saltymouse
    @aj-adl neither of those seem to work. e.g. {{ about.get_field('my_custom_text') }} outputs nothing.

    @aj-adl here's the output of {{ about | print_r }} if you're interested: https://0bin.net/paste/DuYl0SwAb7kTqDqh#qr1D7czCVY1FN7sl9cGudCwIi7zc+BwPMqVpSIvBlgw

    the actual name of the field I want is top_only (as it appears in that output)

    saltymouse
    @saltymouse
    this is all in a fresh local test project.
    • PHP 7.3.1
    • WP 5.2.1
    • ACF Pro 5.8.1
    • Timber 1.9.2 (installed from WP Plugin Manager)
    • Timber Starter (master Github branch)
    saltymouse
    @saltymouse
    switching from new Timber\PostQuery(8) to new Timber\Post(8) allowed me to access the text-field with the meta function! but not the repeater field on the same page...
    Lukas Gächter
    @gchtr
    @saltymouse Did you initialize Timber with new Timber\Timber(); in functions.php (https://timber.github.io/docs/getting-started/setup/#via-github-for-developers)?
    saltymouse
    @saltymouse
    @gchtr I'm using the official starter-theme ... do I still need that?
    I'm not getting that "Timber not activated" warning (plugin is active) so I assumed it's working...
    (Plus non-ACF Timber actions seem to work fine)
    Lukas Gächter
    @gchtr
    @saltymouse Oh sorry, no in that case you wouldn’t need that.
    Lukas Gächter
    @gchtr
    I see that you’re using Timber\PostQuery for querying a single post? A post query returns an array of posts. So if you don’t loop over that array in your singular post, you will not be able to access your custom field value. What happens if you use $context['about'] = new Timber\Post( 8 );?
    saltymouse
    @saltymouse
    @gchtr Yeah, I switched to $context['about'] = new Timber\Post( 8 ); and I can now access simple ACF text fields properly. e.g. {{ about.meta('my_text') }} ... but NOW I can't figure out how to loop over my ACF repeater in the same post ID context...
    saltymouse
    @saltymouse
    <p>{{ about.meta('top_only') }}</p> {# This works! #}
    
    {% for slide in about.meta('slider') %}  {# Does NOT work :( #}
      {{ Image(slide.image_desktop).src }}
    {% endfor %}
    
    <pre>{{ about.meta('slider') | print_r }}</pre> {# Is this output normal? #}
    print_r output → https://0bin.net/paste/h1ka0oUl7Qj5Ai2i#NKyHr+j55DE3h16z6YQ2myHzcSslNN4BRFbhbJxP14U
    saltymouse
    @saltymouse
    the link ACF field is a relational/internal WP link... that's why it's showing the "Hello World" sample page
    BTW, if I add some some random text in that for loop, it prints out twice (correct number of 'slides')... so the loop bit is working fine
    Lukas Gächter
    @gchtr
    @saltymouse When you look at the output you’re getting, you have an array with two elements. And each of the elements has a slide element that contains your values. So it would actually be {{ Image(slide.slide.image_desktop).src }}, because you have to access the slide element first:
    {% for item in about.meta('slider') %}
        {{ Image(item.slide.image_desktop).src }}
    {% endfor %}
    saltymouse
    @saltymouse
    @gchtr Ah! That's it! Looks like I just didn't pay attention to how I constructed my ACF repeater... rookie mistake! No Timber problems after all. Thanks for the help!
    Lukas Gächter
    @gchtr
    @saltymouse Nice you got it working! No worries, we’ve all been there ;)
    Sander Scheijbeler
    @sanderscheijbeler

    Hi all, im back with another challenge :S

    I have been trying to create a mega menu using widgets..

    what have i done so far:

    public function wpmm_init() {
            $location = 'megaMenu';
            $css_class = 'has-mega-menu';
            $locations = Timber\Timber::context()['navigation'];
            if ( isset( $locations[ $location ] ) ) {
                $menu = get_term( $locations[ $location ], 'nav_menu' );
                if ( $items = wp_get_nav_menu_items( $menu->name ) ) {
                    foreach ( $items as $item ) {
                        if ( in_array( $css_class, $item->classes ) ) {
                            register_sidebar( array(
                                'id'   => 'MegaMenuWidget',
                                'name' => $item->title . ' - Mega Menu',
                            ) );
                        }
                    }
                }
            }
        }

    I registered 3 "MegaMenuChild" menu's, 1,2 and 3.
    And i have checked within my menu.twig

    {% if 'has-mega-menu' in item.classes %}
                    <div class="mega-menu__container">
                        <div class="mega-menu-col mega-menu-col-1">
                            {% include "navigation/menu.twig" with {'menu': navigation.megaMenuChild1.get_items, 'level': 'children'} %}
                        </div>
                        <div class="mega-menu-col mega-menu-col-2">
                            {% include "navigation/menu.twig" with {'menu': navigation.megaMenuChild2.get_items, 'level': 'children'} %}
                        </div>
                        <div class="mega-menu-col mega-menu-col-3">
                            {% include "navigation/menu.twig" with {'menu': navigation.megaMenuChild3.get_items, 'level': 'children'} %}
                        </div>
                    </div>
                {% else %}
                    {% include "navigation/menu.twig" with {'menu': item.get_children, 'level': 'children'} %}
                {% endif %}

    This works (dont ask why or how!)... But within the widget i have used the navigation widget to select one of the 3 menu's i have created to be displayed etc. That also has a title.

    My question: How do i display that title?!
    I was thinking

    $content['footer_widgets'] = Timber::get_widgets( 'MegaMenuWidget' );

    but after dumping this, NULL seems to be the answer.. Im lost. Please help!

    Sander Scheijbeler
    @sanderscheijbeler

    I realise i did alot of stupid things in the examples above...
    So i tried to do the following: (timber/timber#946)
    Following the persons "update" to how he got the widget to display..

    Only to find that i could not get any widget to display using
    <p>{{dynamic_sidebar}}</p>
    $context['dynamic_sidebar'] = Timber::get_widgets('home_sidebar');

    But when i made it into a function i did get some output, but also with a 1 underneath it, wich (when used var_dump) was a boolean?!

    How do you people use widgets and why is this not working?!

    saltymouse
    @saltymouse
    Quick question: when trying to output the URL from an ACF "Page Link", is there a more Timber-y way than using default WP functions, e.g. {{ fn('get_page_link', slide.link) }}?
    slide.link gives the linked page ID like this: Array([0] => 1)
    Lukas Gächter
    @gchtr
    @sanderscheijbeler Would you mind opening a new question on Stack Overflow for this? It’s a little easier to handle questions involving bigger code examples.
    @saltymouse Currently, there’s not. I usually use get_permalink for this: {{ fn('get_permalink', slide.link) }}.
    saltymouse
    @saltymouse
    @gchtr Good to know! Thanks for the alternative, too :)
    akolbo
    @akolbo
    Hey everyone, I just posted a question on Stackoverflow, but I was wondering if there was a way to use some of the twig Timber filters for a non WordPress setup. Reason would be to mockup a site quickly in a basic Twig setup without WP, then be able to easily port the code over to WP Timber once complete. Then worry about custom post types and fields after that. https://stackoverflow.com/questions/57023363/timber-plugin-for-use-in-non-wordpress-twig
    saltymouse
    @saltymouse
    I'm currently working on translating the Timber docs into Japanese for my colleagues. Anyone know how the "Reference" section is generated from the PHPDoc comments?
    Sander Scheijbeler
    @sanderscheijbeler

    Hi all,

    Im getting an error when i tried out my theme..

    Uncaught Twig_Error_Syntax: Unexpected token "operator" of value ">"

    Talking about the following it of code:

    {{ post.tags|map(t => t.name)|join(', ') }}

    I dont see why this would resort in an error?! Does anybody have an idea?

    Sander Scheijbeler
    @sanderscheijbeler
    Ok. So this is weird. I found out that my timber plugin (1.9.2) that i installed online was using an older version of twig. But within my local env i had twig version 1.41 so thats why the map filter worked...
    I uploaded my local timber plugin and now it works :(
    Ricky Green
    @rgcouk
    Anyone active, need little help in not including an input if it hasn't been changed in a search query.
    akolbo
    @akolbo
    Can you provide more?
    Jayce Dugan
    @JDevx97

    Hey everyone,

    If anyone's a VS Code user I've published a shorthand snippets extension for Timber.

    "Timber Snippets"

    Available here: https://marketplace.visualstudio.com/items?itemName=jdcreations.timber-snippets&ssr=false#overview and open to changes here https://github.com/JDevx97/Timber-Snippets

    Repo: https://github.com/JDevx97/Timber-Snippets

    Enjoy! Open to any updates / changes.

    Frank Asante
    @frankplay
    Question: How do I use Timber via composer. I'm not as familiar with composer and just want to see how it works with composer.
    Sander Scheijbeler
    @sanderscheijbeler
    You can just require "wpackagist-plugin/timber-library":"1.15.1" as a plugin in your composer file and work with it
    Ricky Green
    @rgcouk
    Anyone alive in here please?
    I'm looking to get the file url
    Alexander Seredenko
    @aseredenko

    Hi guys, I’ve started to use timber in my wordpress project and I really like the conception, but the problem I faced is that .twig files can’t be edited from the admin panel.

    I wasn’t able to google anything. Is this possible at all?

    Thanks

    akolbo
    @akolbo
    I believe this type of workflow is more fit for manual templating via a code editor like VS Code or Sublime text rather than handling any changes to your .twig files via the admin panel.
    Dejan Pavlic
    @dpavlic
    This is almost certainly a silly question, but here goes... I am not planning to use Timber for theme development. I have a custom plugin that adds a page with some logic to an admin menu. I want to render out the html logic using Twig within the plugin, but pretty much all the WP examples I google route me to Timber... Is there any reason for me to use Timber vs. just bootstrapping twig within my plugin?