Skip to content

Instantly share code, notes, and snippets.

@jasperf
Last active April 15, 2025 02:39
Show Gist options
  • Save jasperf/3f95bf47fadb9418a27195f212d3889f to your computer and use it in GitHub Desktop.
Save jasperf/3f95bf47fadb9418a27195f212d3889f to your computer and use it in GitHub Desktop.
ACF Composer Blocks vs Block Patterns in Nynaeve Theme

πŸ› οΈ ACF Composer vs. Block Patterns in setup.php

πŸ” Overview

ACF Composer (by Log1x) excels at defining ACF Blocks and Field Groups in a structured, object-oriented way using PHP classes.

While you could use ACF Composer to register block patterns, it doesn’t offer a significant advantage over your current method via setup.php β€” especially when it comes to layout-based patterns.


βœ… Your Current Approach: setup.php for Patterns

You're already following a common and valid method:

  • Defining patterns as PHP files containing block markup
    e.g., faq-pattern.php, modern-pricing-table.php
  • Reading these files and their metadata in setup.php
  • Registering them using the standard register_block_pattern() function
  • Styling them in app.css and editor.css

This setup works well for layout-based, reusable block patterns.


🧩 Using ACF Composer for Pattern Registration (Optional)

If you wanted to centralize pattern registration in ACF Composer, you would typically:

  1. Create a dedicated Composer class for each pattern, or use a service provider.
  2. Inside that class/provider:
    • Read the pattern file content (like your get_processed_pattern_content() in setup.php).
    • Register it using register_block_pattern().
  3. Remove pattern logic from setup.php.

🧠 This approach centralizes logic, which is nice for consistency if you're already deep into ACF Composer.
However, it doesn't change how the patterns work or render β€” it's more about structure.


πŸ”„ Blocks vs. Patterns: What's the Difference?

πŸ”³ Block Patterns

  • Reusable layouts built with existing core/custom blocks
  • Content is editable within the editor
  • No ACF fields involved
  • Great for static layouts like:
    • Pricing tables
    • FAQs
    • Hero sections

🧱 ACF Blocks (via Composer)

  • Custom block types with specific ACF fields
  • Rendered using Blade templates
  • Perfect for components needing structured data, such as:
    • Testimonial blocks (name, quote, image)
    • Team member blocks
    • Accordions with dynamic content

Your current faq-pattern.php and modern-pricing-table.php are patterns, not ACF Blocks.


βœ… Recommendation

  • Stick with your current method in setup.php for block patterns β€” it's efficient and fully valid.
  • Use ACF Composer when you need to build custom blocks with field input, rendering logic, and better reusability.
  • You're free to mix both methods:
    • Use setup.php for layout patterns
    • Use ACF Composer for field-driven ACF Blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment