-
Notifications
You must be signed in to change notification settings - Fork 28
Code patterns: Initial experiment. #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
} | ||
); | ||
}, | ||
canUserEditValue: () => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check permissions.
This is a very interesting experiment. I'm not entirely sure how I feel about the idea of coding the block pattern using HTML and helper functions. I'm more inclined to explore how to build patterns in the editor interface. However, all the necessary pieces are in place for that use case, so this is an excellent start. |
What
This past week, I’ve been experimenting with different approaches for creating patterns. My requirements were:
The Experiment
I decided to go with the PHP route—it’s simpler and handles loops and conditionals easily. But there are caveats:
We don’t have post context available when registering a pattern.
ACF creates custom blocks as entire patterns and treats each field as an “editable part.” We want to stick with standard blocks inside standard patterns.
I am avoiding parsing the PHP file content. If I was to do that, I'd need to parse the HTML, process the PHP, and then merge everything. That way I could:
Instead, I went for a “just use PHP functions” approach. For example:
This outputs:
This code:
Outputs:
While this works, the developer experience still isn’t as smooth as classic themes.
We can now use the full power of block bindings with our new source, scf/experimental-field. That means fields can be edited directly in the editor UI.
Better yet, those inputs can live in the post sidebar (instead of being buried in metaboxes).
patterns_demo.mov