Site logo

[Resolved] Styling Page Templates with Blocks

Home Forums Support [Resolved] Styling Page Templates with Blocks

Home Forums Support Styling Page Templates with Blocks

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2471754
    Jordy

    Hi Everyone,

    I’ve setup a page template, so that I can dynamically use that with Advanced Custom Fields. Whenever I need to make changes to the design, I just need to go to one template file instead of making the change on every single page.

    Everything is working great, but I have a concern.

    Can I simply design a page using blocks and then copy that code over to the template php file? It definitely works, but I’m worried that with future updates of both WordPress and Generatepress, the blocks might break? Because I assume that with updates, the style to these blocks could also update? But since I will hard-code this into the template file, they won’t get updated.

    If my concern is correct, is there a better way to do this?

    Thank you in advance!
    Jordy

    #2471872
    Ying
    Staff
    Customer Support

    Can I simply design a page using blocks and then copy that code over to the template php file?

    It’s not recommended. Why not use a block element - content template for the pages?
    https://docs.generatepress.com/article/block-element-content-template/

    #2471917
    Jordy

    Thank you Ying,

    This seems like a good solution.

    However, I don’t see the possibility to write PHP in here. I need to add dynamic content from the Advanced Custom Fields.

    Or am I missing something?

    Best,
    Jordy

    #2471925
    Ying
    Staff
    Customer Support

    However, I don’t see the possibility to write PHP in here. I need to add dynamic content from the Advanced Custom Fields.

    You can pull dynamic data from ACF fields using headline block/buttons block/image block from GenerateBlocks.
    https://docs.generateblocks.com/article/headline-overview/#dynamic-data

    #2472195
    Jordy

    As far as I see, content templates only work for posts and a limited amount of ACF fields?

    I need to work with some ‘if else’ statements and only apply my template for specific pages, not posts.

    But it’s very nice to know about content templates though! I might wanna restyle my blog posts using this technique.

    #2472305
    David
    Staff
    Customer Support

    Hi there,

    you can use the Block Element Content Template for Posts, Pages and Archive pages.
    If you have Custom templates then using the themes templates as a starter will allow you to also use the content template there.

    For targeting specific pages or posts, you can define those in the Block Element Display Rules.

    In addition to that, if a GB Block is set to display a custom field, and the value is empty then it won’t output any HTML.
    There is also a Display Condition for the GB Container Block ( whilst in a GP element ) that can be used to remove a block if a Post Meta field is empty for example.

    You can do lots with them, but there are limitations. For example you cannot currently use nested / repeater fields from ACF. And you can’t query the meta in the template aside from using the conditions i mention in the paragraph above. In those instances you could add shortcodes inside a GB headline block so you can still style it in the editor.

    #2472812
    Jordy

    Thanks for the support guys, I figured it out!

    I explored the content templates a bit more and I can do most things with it. The ACF support in GenerateBlocks is amazing! For the extra functionality I needed, I simply created custom shortcodes. So now I can use my shortcodes in the content template.

    A great solution that involves little custom code!!

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