- This topic has 6 replies, 3 voices, and was last updated 2 years, 8 months ago by
Jordy.
-
AuthorPosts
-
December 23, 2022 at 9:01 am #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!
JordyDecember 23, 2022 at 12:26 pm #2471872Ying
StaffCustomer SupportCan 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/December 23, 2022 at 2:05 pm #2471917Jordy
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,
JordyDecember 23, 2022 at 2:14 pm #2471925Ying
StaffCustomer SupportHowever, 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-dataDecember 24, 2022 at 3:14 am #2472195Jordy
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.
December 24, 2022 at 6:17 am #2472305David
StaffCustomer SupportHi 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.
December 25, 2022 at 4:14 am #2472812Jordy
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!!
-
AuthorPosts
- You must be logged in to reply to this topic.