Adding files with gt add
gt add is the scaffolding command. It creates starter files for common WebEngine project types so we do not have to remember the exact directory structure or write the initial boilerplate by hand.
What it can create
The command currently supports three types:
pageapicron
Basic usage:
gt add type name [template]
Examples:
gt add page about
gt add api status
gt add cron cleanup
What files get created
Pages
gt add page about
Creates:
page/about.html
page/about.php
The built-in page template contains a heading and paragraph in the HTML file, and an empty go() function in the PHP file.
APIs
gt add api status
Creates:
api/status.php
api/status.json
This gives us a PHP handler and a starter JSON Schema file describing request and response shapes.
Cron scripts
gt add cron cleanup
Creates:
cron/cleanup.php
That file contains a starter go() function that can be called from a crontab entry.
How names are validated
The name part may contain:
- letters
- numbers
- hyphens
- underscores
If another character is used, the command stops with an error rather than creating awkward or invalid paths.
Built-in templates
When no template name is supplied, gt add copies files from this package’s own template directory:
src/Template/page/template.htmlsrc/Template/page/template.phpsrc/Template/api/template.phpsrc/Template/api/template.jsonsrc/Template/cron/template.php
Any {{name}} placeholder inside those template files is replaced with the name passed on the command line.
Project templates
If a template name is supplied, gt add looks in the current project instead of using the built-in files.
For example:
gt add page about marketing
This looks for files matching:
page/_template/marketing.*
If marketing.html and marketing.php exist there, they will be copied to:
page/about.html
page/about.php
The same pattern works for the other supported types:
api/_template/<template>.*cron/_template/<template>.*
This is a useful way to keep team-specific starter files in the project itself.
A few practical details
- The destination directory such as
page/,api/, orcron/is created automatically if it does not already exist. - Existing destination files are never overwritten.
- If a named project template does not exist, the command stops and explains which directory it checked.
[!NOTE] In WebEngine,
gt add page ...maps directly onto the framework’s page conventions: HTML view inpage/, matching PHP logic inpage/, and a URI derived from the filename. That is why this command is such a common starting point in new projects.
Next, continue with Creating a new WebEngine application if you want to see how gt create bootstraps a whole project rather than just individual files.