Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Steve Pfisterer
    @stevep
    you prefer blade to twig?
    Marko Bolliger
    @cannap
    its simpler
    but atm i like twig
    i know blade from laravel
    i dont know what changed with the time
    best would be vuejs :D
    Steve Pfisterer
    @stevep
    i’ve not used. to me its like handlebars (twig) vs haml (blade) but ive not looked into it really
    Marko Bolliger
    @cannap
    but php cant handle ssr with vuejs
    nunjuck is more like twig
    from mozzila
    i do much js then i need to rethink so much stuff
    but blade i know
    @ stuff is nice
    sry my english is not so good
    maybe i write something wrong xD
    Steve Pfisterer
    @stevep
    ya sometimes its hard to transition between langauges / environments
    (programming languages)
    big context switch
    Marko Bolliger
    @cannap
    yea i use js without ";"
    and then i write php forgot everytime to terminate
    the line
    Steve Pfisterer
    @stevep
    ive changed over to phpstorm full time and it will yell at me, good for catching bugs
    Marko Bolliger
    @cannap
    are you using xdebug?
    Steve Pfisterer
    @stevep
    Sometimes, it can be very useful
    Lara Schenck
    @laras126
    Hey all! Question: what is the purpose of header.php and footer.php in a Timber theme? It looks to me like they just add output buffering, but is that used at all in Timber itself, Or just there for plugins/whatever?
    Jared Novack
    @jarednova
    @laras126 it's for some plugins like Events Calendar Pro and WooCommerce that need explicit header/footer.php files for whatever reason
    Ricky Green
    @rgcouk
    Hello all. :)
    Looking for a little bit of direction, i would like to display woocommerce cart view in the header, basic icon, total and number or items, i've been search google but i can't find anything relevant.
    Ricky Green
    @rgcouk
    Anyone around?
    Ricky Green
    @rgcouk
    Morning.
    Lukas Gächter
    @gchtr
    @rgcouk Hi Ricky. No worries, people read this channel and if they have an answer, they’re happy to help. Questions about WooCommerce and Timber come in from time to time (https://gitter.im/timber/timber?at=587fc42711e7a7f61db2db24). But solutions for integrating WooCommerce with Timber are sparse, I guess.
    Ricky Green
    @rgcouk
    Hello Lukas, Thanks for your input, ill check that link out.
    Ricky Green
    @rgcouk
    Hmm, Okay, I basically want the cart view in the header without a plugin.
    Ricky Green
    @rgcouk
    @gchtr You still around please?
    Lukas Gächter
    @gchtr
    @rgcouk I’m afraid I can’t help you with WooCommerce, because I don’t use it.
    Ricky Green
    @rgcouk

    Yes, thats fine, but you maybe able to shed some light on something for me?

    I've copied over mini-cart.php and importing it to my twig file but it display the PHP code, I'm guessing i've got to covert it to twig and call it like i do the other pages? $context['cart'] = WC()->cart->get_cart();, i just need to know if theres a standard, not going to say easy way because i know that rarely exists

    Lukas Gächter
    @gchtr

    @rgcouk The starting point for working with WooCommerce seems to be http://timber.github.io/timber/#woocommerce. That’s probably the only standard that exists.

    When using Timber, you don’t necessarily have to convert everything to Twig. You could still use PHP. If you need the output of a PHP file in a Twig file, something like this might work:

    ob_start();
    include ('path/to/mini-cart.php');
    
    $context['minicart'] = ob_get_contents();
    ob_end_clean();

    As you assumed, importing PHP code directly into Twig won’t work, so you’d have to convert it to Twig. Something like this might work:

    $context['cart'] = WC()->cart;

    In your Twig file you could maybe do something like this:

    
    {% if not cart.is_empty }
        {% do action( 'woocommerce_before_mini_cart_contents' ) %}
    
        {% for cart_item_key, cart_item in cart.get_cart %}
            {% set product = fn('apply_filters', 'woocommerce_cart_item_product', cart_item.data, cart_item, cart_item_key)}
    
            {# … #}
        {% endfor %}
    {% endif %}
    Ricky Green
    @rgcouk
    Thanks @gchtr I'm going to read over this.
    Much appreciated

    Do i wrap {%
    ob_start();
    include ('woocommerce/cart/mini-cart.php');

    $context['minicart'] = ob_get_contents();
    ob_end_clean();
    %}

    Sorry, i'm newbie at twig, only started yesterday.
    Lukas Gächter
    @gchtr
    That’s okay. Everyone started like you. And no, that’s the part you would use if you don’t want to convert mini-cart.php to Twig. You’d probably use that in the PHP file where you load the rest of the header. In the twig file where you’d want to display the minicart, you would then do {{ minicart }} to output the contents from mini-cart.php. But I can’t tell you if that works. As I said, I’m not familiar enough with WooCommerce.
    Ricky Green
    @rgcouk
    Arg, i think i get it, slowly, ha, thanks for being understanding :D
    Ricky Green
    @rgcouk
    Last thing i'll annoy you with @gchtr Do you know why i'm getting random numbers put into my website, i've had a floating "1" for a while, since i've been doing those bits i have a "0" next to where the cart should be.
    Lukas Gächter
    @gchtr
    @rgcouk Could be a function output that returns true (1) or false (0), which is directly echoed. This could come from your theme, or from a plugin.
    Steve Pfisterer
    @stevep
    ob_get_clean() without ? Sorry my formatting got messed up
    Lukas Gächter
    @gchtr
    So that would be $context['minicart'] = ob_get_clean();, without the ob_end_clean(), I guess?
    Steve Pfisterer
    @stevep
    Maybe... I should have prefaced it with "trying using". Though if it was happening before it probably isn't the issue