Opened 2 years ago
Last modified 10 months ago
#56847 new defect (bug)
Template parts and patterns
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.0.3 |
Component: | Editor | Keywords: | close |
Focuses: | template | Cc: |
Description
Good day,
I am developing a WordPress theme (published, but still work in progress, W3CSSPress).
While I was trying to get a value from a function (in functions.php) into a component of the theme I noticed a strage behavior.
If I try to develop a normal template part in HTML and include in it a pattern which contains a dynamic content, then I move away the templates and reload the website (classic version of the theme) and then I move back the templates (block version of the theme) I find that the dynamic generated part got cached and is not generated again anymore.
Istead, if I avoid to use a template part and I put its content inside a pattern and I call it from the templates of the pages (like, front-page.html) the content gets dynamically regenerated correctly.
This could be a good behavior from a caching and performance point of view, but if a template part has got some dynamic content it should be regenerated.
Is it fixable in some way?
Hi @matteomarchiori97
It is not perfectly clear to me how to reproduce the issue. I did not understand from the description if the problem is with template parts not loading inside patterns, or, if it is a problem when changing a block theme to a classic theme and back.
To prevent caching of various Site Editing features, theme developers can set
WP_DEVELOPMENT_MODE
totheme
:https://make.wordpress.org/core/2023/07/14/configuring-development-mode-in-6-3/
Patterns can not contain truly dynamic content, because as soon as a pattern is placed in the content, it is no longer a pattern, just blocks, and whatever was generated by the PHP in the pattern is static, saved to the database with the rest of the content.
One way around this, is to use the new block bindings api, but it is only a partial solution.
https://make.wordpress.org/core/2024/03/06/new-feature-the-block-bindings-api/
I suggest closing this ticket because I believe it is a question about implementation, rather than a bug.