Usually, scaffold files are copied into place without modification. In some instances, it may be useful to do string replacements on the contents of a scaffold file before writing it to its destination. For example, a scaffolded .gitignore file could contain paths that are relative to the webroot; these may be fixed up via the interpolation process.
The example below shows a replace operation with the interpolate option enabled:
{
"name": "service-provider/d8-scaffold-files",
"extra": {
"drupal-scaffold": {
"file-mapping": {
"[project-root]/.gitignore": {
"mode": "replace",
"path": "assets/example.gitignore",
"interpolate": true,
"overwrite": false
}
}
}
}
}
When interpolation is enabled, then all of the locations (see "Defining Project Locations", above) are available as substitutions within the content of the file being scaffolded. In addition, a [vendor] key is available to provide the path to the Composer vendor directory.
An example.gitignore scaffold file could use these substitutions as shown in the example below:
# Do not commit the 'vendor' directory
[vendor]
# Do not commit files copied by the scaffold plugin
[web-root]/index.php
When this file is scaffolded on a site where web-root is defined to be docroot in the composer.json file, then the file written to the scaffold file's destination location will look something like this:
# Do not commit the 'vendor' directory
vendor
# Do not commit files copied by the scaffold plugin
docroot/index.php