[Resolved] [GP 3.0] Custom page template – how to?

Home Forums Support [GP 3.0] Custom page template – how to?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1477304
    AdB

    Hi, I’ve a question related to the 3.0 version of Generate Press.

    Like I already asked here https://generatepress.com/forums/topic/custom-page-template-how-to/ for the previous version, now I’d like to know how can I create a custom page template for the 3.0 (always because I’ll use Advanced Custom Fields and a Child Theme – not using Blocks)

    I couldn’t find anything (yet?) in the documentation, only these:
    https://generatepress.com/generatepress-3-0-a-new-era/ —> generate_do_template_part()

    and

    https://generatepress.com/forums/topic/generate_do_template_part-does-not-call-the-content/#post-1450158
    https://generatepress.com/forums/topic/question-about-gp-3-0-and-generate_do_template_part/#post-1429909

    but still it’s pretty unclear.

    Also, should I do something about the custom page templates (of a child theme) created with the old version of Generate Press or should they stay like they are? (I already updated my test-site, and everything is working fine..)

    thank you!
    Davide

    #1477450
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    There’s no issue with keeping your child theme get_template_part() as it is right now.

    You will want to do a quick comparison to make sure the other parts of the template files match with the new version, but the actual get_template_part() can stay as is.

    #1477516
    AdB

    ok thanks.
    and how can I create a new custom page template with GP3.0?

    I’ve to make a copy of the page.php file, renamed it. After that, how can I “link” the template with the contents (—> content-page.php)?

    Should I use generate_do_template_part in the (copy of) page.php file?
    thanks
    D.

    #1478831
    Tom
    Lead Developer
    Lead Developer

    What are you wanting to customize in this template, exactly? Which part of the default template are you wanting to alter/replace?

    #1479073
    AdB

    Hi Tom,
    maybe I didn’t express myself good enough 😀

    I’m using advanced custom fields, so I need a specific template for some pages in order to output there the contents (repetition fields, flexible contents, etc.).
    So, to replace the entire content of a page with the contents of the advanced custom fields.

    The original question is:
    How can I create a custom page template in GP 3.0?
    Back then, you’ll need to make a copy of the page.php, rename it (let’s say in kontakt.php), then make a copy of the content-page.php file, rename it (content-kontakt.php) and then “link them” together by changing this in the kontakt.php page

    while ( have_posts() ) : the_post();
      get_template_part( 'content', 'kontakt' );
    

    With the version 3.0, the page.php file has this instead

    if ( generate_has_default_loop() ) {
         while ( have_posts() ) :
    
    	the_post();
    
    	generate_do_template_part( 'page' );
    
         endwhile;
    		}

    Does it make sense to change the function “generate_do_template_part( ‘page’ );” with “get_template_part( ‘content’, ‘kontakt’ );” in order to create a custom page template?
    If not, how can I use the function “generate_do_template_part() to achieve what I’d like to achieve?

    Thank you!
    D.

    #1480668
    Tom
    Lead Developer
    Lead Developer

    Yes, if you need to create custom template files, you can replace generate_do_template_part( 'page' ); with your own get_template_part( 'content', 'kontakt' ); function.

    Depending on what you’re doing to these files, it may not be necessary to create custom template files, but if you do need to, the above is the method to use.

    #1483268
    Caroline

    Hi Tom – are you planning on putting together any documentation on how to use generate_do_template_part in child themes? I’ve literally just got my head around how to use get-template-part with ACF (similar to the OP) to make custom designs, only to find that GP is no longer using it! 😂😂😂

    If possible, it would be great to understand how to use generate_do_template_part in similar situations.

    Also – I understand you’re saying get-template-part will still work in the child theme, but is there any likelihood of conflicts with the parent theme in the future?

    Thanks so much!

    #1483649
    Tom
    Lead Developer
    Lead Developer

    Yes, I’ll be writing some docs on it.

    generate_do_template_part() is just a wrapper for get_template_part() – the benefit is that we can now turn off/replace get_template_part() using conditions without having to create child themes.

    There’s nothing extra to learn or do if you’re already using child themes with get_template_part() – it all works exactly as it did before.

    This new method will simply give us more flexibility without needing custom template files 🙂

    #1483758
    Caroline

    Great – thanks for confirming that Tom!
    Caroline

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