[Resolved] Question about GP 3.0 and generate_do_template_part

Home Forums Support Question about GP 3.0 and generate_do_template_part

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1429816
    Espen

    Hi,

    I’m curious about the new generate_do_template_part in GP 3.0. I’m looking to redesign my current website and move it over to GP, so I am testing out GP. So far I’m really liking the focus on clean and fast code!

    Some questions:

    In the GP 3.0 Alpha launch post it says “Imagine building your custom templates as Block Elements and dynamically displaying them in place of the standard theme loop across your site.”

    I may be way off here, and please correct me if I am but:

    1. Does this mean that we will be able to for instance design custom category pages with the block editor? And have control of the layout of the loop itself on those pages?

    2. If so, will it work with the visibility controls in GPP so that I can for instance have different category loop layouts for different categories?

    3. Won’t this require a sort of display posts block, to replace the loop with?

    4. What about dynamically pulling in metadata such as the current category etc?

    4. It looks as if the generate_do_template_part in GP 3.0 opens up a lot of possibilities, but to really use them I guess we will need a new version of GPP? Is that correct, and if so when can we expect it? 🙂

    Great job on GP 3.0. I’ll continue to test it out and let you know if I discover anything buggy 🙂

    Best Regards,

    Espen

    #1429909
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Great questions!

    1. That’s correct. This action will allow us to build post loop templates in Block Elements, and then hook them into the theme.

    2. Full control with Display Rules – different designs for different archives etc..

    3. Not necessarily. We’re introducing Template Tags (like in the current Header Element) into Block Elements in GPP 1.12.0. This will allow you to dynamically pull in data from the current post object while using the Headline Block in GenerateBlocks. Post titles, post meta etc..

    4. See above.

    5. Yes, if you’re wanting a full UI to build with. You can, of course, use code:

    // Disable the core template part on the blog page.
    add_filter( 'generate_do_template_part', function( $do ) {
        if ( is_home() ) {
            return false;
        }
        return $do;
    } );
    
    // Add our own.
    add_action( 'generate_before_do_template_part', function() {
        if ( is_home() ) : ?>
            <article <?php post_class(); ?>>
                <div class="inside-article">
                    <h1><?php the_title(); ?></h1>
                    <a class="button" href="<?php the_permalink(); ?>">Read more!</a>
                </div>
            </article>
        <?php endif;
    } );

    It’s basically a way to replace the theme loop without using child theme files.

    Hope this helps! Thanks for testing 3.0 🙂

    #1429947
    Espen

    That sounds fantastic, Tom!

    I’m very excited to start playing with all the new functionality 🙂

    -Espen

    #1430989
    Tom
    Lead Developer
    Lead Developer

    Definitely a lot of cool things that can be done now! 🙂

    #1445373
    Craig

    Hi,

    I have recently upgraded to GP premium 1.12.0-alpha.1 and I’m not able to see any option for generate_do_template_part or generate_menu_bar_items in the elements hook options. Am I possibly missing something or am I just to premature to test these features?

    Testing GP 3.0 and aside from my confusion above, so far so good. Thanks!

    #1445397
    David
    Staff
    Customer Support

    Hi there,

    generate_menu_bar_items is a standard action hook – it will be added to the Elements list in the next update. In the meantime you can manually add it by selecting the Custom Hook.

    generate_do_template_part is more complicated then that and will be something that GPP will integrate in a future update. In the meantime the code method Tom provided is the way to go.

    #1445424
    Craig

    That’s great! Thanks David. Really pleased with what you guys have come up with for 3.0

    Keep up the good work!

    #1445455
    David
    Staff
    Customer Support

    Glad to be of help – and thanks for the great feedback.

    #1454386
    Samuel

    Just to make sure I fully understand what’s available with generate_do_template_part currently.

    It sounds like using Elements linked to generate_do_template_part you can use the block editor to replace the loop for specific content.

    We need a new GPP to be able to use a block element with dynamic content (i.e. a block layout where you can replace title, excerpt, post, categories, etc with data at run time).

    Is there any way in PHP code to tell GP to display a block element or are we limited to using the Elements UI to select where an element shows?

    #1455740
    Tom
    Lead Developer
    Lead Developer

    You could definitely use code to insert a Block Element into that hook. The issue right now is making it so the Block Element works nicely within the loop. There are some issues there we need to figure out before it will work perfectly.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.