Documentation-Issue-Tracker icon indicating copy to clipboard operation
Documentation-Issue-Tracker copied to clipboard

Specify difference between Pattern and Template/Parts files in docs (i.e. PHP vs HTML)

Open feragnoli opened this issue 8 months ago • 1 comments

Issue Description

The Patterns chapter does not clearly specify that, unlike template and template-parts files (HTML), pattern files in a theme are PHP files

URL of the Page with the Issue

https://developer.wordpress.org/themes/patterns/introduction-to-patterns/

Section of Page with the issue

Introduction to patterns

Why is this a problem?

The fact that patterns should be saved as /patterns/hero.php (php files) is briefly mentioned in the following chapter (Registering patterns) whereas all 'reusable component' files described in the structuring of a block theme up to this point are expressly referred to as being html files

Suggested Fix

Stress that, unlike the files that go inside /templates and /parts, pattern files are php files and to do so both in 'introduction to Patterns' and in 'Registering patterns'

feragnoli avatar Mar 22 '25 22:03 feragnoli

Heads up @WordPress/docs-issues-coordinators, we have a new issue open. Time to use 'em labels.

github-actions[bot] avatar Mar 22 '25 22:03 github-actions[bot]

We can add a Para like this to stress on these points,

  • Unlike template and template part files, which are written in .html, pattern files must use the .php extension (e.g., hero.php) and are stored in the /patterns directory. This is because patterns are registered via PHP and may include localization functions or dynamic logic. It's important to follow this convention when organizing your block theme to ensure patterns are recognized and function properly.

  • Example Folder structure -:

my-theme/
├── templates/
│   └── index.html
├── parts/
│   └── header.html
└── patterns/
    └── hero.php

Anuj-Rathore24 avatar Jul 01 '25 11:07 Anuj-Rathore24

That would be clear. I’d stress that is probably important to specify tgat (or provide a link to this point) in both ‘registering patterns’ and ‘introduction to patterns’ since one can’t give for granted a ‘linear’ fruition of the docs

feragnoli avatar Jul 06 '25 11:07 feragnoli