i think the book refers to the old scr/ folder that now is called app/ ? i’m a little confused.
if you want to add a new custom type for example the place to live will be for example /app/cpt/ ?
where do i point sage to read that custom post types?
Hey @francisco_arenas - yes, that’s correct, the src
folder is now app
.
Arguably the best way to add a CPT would be to create a small plugin for it, so that the CPT isn’t coupled to the theme.
But to add a new PHP file to the theme (whether it’s registering a CPT or doing anything else you might need) and let Sage know to load that file, just add the file (e.g., mynewfile.php
) to the app
folder, and then edit functions.php
:
**
* Sage required files
*
* The mapped array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*/
array_map(function ($file) use ($sage_error) {
$file = "../app/{$file}.php";
if (!locate_template($file, true, true)) {
$sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
}
}, ['helpers', 'setup', 'filters', 'admin', 'mynewfile', ]);
The last line I included there defines an array of the files that Sage loads from the app
folder (besides the controllers), with a new item for mynewfile
.
The book seems to refer to a wrong folder path here (in current Sage version the folder is called app
).
Though I’d like to see the folder name changed in future Sage versions. Why? Bedrock also has a folder called app
, so the full path is: /web/app/themes/sage/app
. This sometimes causes a little confusion and disorientation for our developers when working in the IDE.
thanks for this, that was exactly what i was looking for