---
title: "Custom Stubs"
description: "Change the templates that Crest fills in: copy a stub into your project with stub:publish."
version: "1.0"
---

> Documentation Index
> Fetch the complete documentation index at: https://crest.phalcon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Stubs

A stub is a template that Crest fills in (see [Stubs](/1.0/how-crest-works#stubs)). To change a stub, copy it into `resources/stubs/<flavor>/` in your project. Crest then uses your copy, not the packaged stub. A stub that all flavors use, for example `command.stub`, is in `resources/stubs/shared/`. Crest looks for a stub in this order: your `resources/stubs/<flavor>/`, your `resources/stubs/shared/`, then the same two folders in the package. `crest stub:publish` copies each stub into the folder where Crest looks for it.

`stub:publish` copies a `project-*` stub, which `new` uses, only when you give its name. See [Project stubs](#project-stubs).

## Project stubs

`crest new` writes the files of a project from the `project-*` stubs (see [Creating a project](/1.0/creating-a-project)). To change them, publish them by name in the folder that the project goes into (the working directory, or `--directory`), then edit the copies. For example, `project-front` is the stub of the front controller. A project stub needs no `crest.php`. `--flavor` gives its flavor, as for `new`; the default is `mvc`:

**MVC**

```bash
crest stub:publish project-front
```

**ADR**

```bash
crest stub:publish project-front --flavor=adr
```

The project stubs that are the same in both flavors are in `resources/stubs/shared/`, and a publish puts them there. A copy in `resources/stubs/<flavor>/` wins over the shared copy for that flavor, and a publish of the shared copy prints a note that names it. Crest looks for a project stub in the order of [Custom stubs](/1.0/stubs). When the flavor does not have the stub and another flavor does, the error names the option to use, for example `pass --flavor=mvc`.

A publish with no name leaves the project stubs out, because they do nothing inside a project. It also leaves the fragment stubs (`fragment-*`) out. They hold pieces of the framework API and the guidance text that the generators print. A copy of a fragment does not get the changes of later releases. Publish a fragment by name to change it.

You can change each project stub on its own. The names that the stubs and Crest must agree on come from these placeholders:

- `{{ documentRoot }}`: the web root folder, `public`
- `{{ router }}`: the router script, `.htrouter.php`
- `{{ portVariable }}`: the port variable, `APP_PORT`
- `{{ port }}`: the default port, `8080`
- `{{ front }}`: the name of the front controller class, `AppFront`
- `{{ source }}`: the source folder, `src`
- `{{ autoloader }}`: the autoloader, `vendor/autoload.php`

Keep these placeholders where the packaged copy has them. Then `serve`, `init` and the generated files agree.

`project-front`, `project-config` and `project-index` must also agree with each other on the namespace. `new` decides where each file goes: a stub cannot move its file. A published copy must use only the placeholders of the packaged copy. If a placeholder has no value, `new` stops before it writes a file.

In an MVC project, `{{ controllerNamespace }}`, `{{ controllerPath }}`, `{{ providerNamespace }}`, `{{ providerPath }}` and `{{ viewsPath }}` come from the default paths of the flavor. A stub that depends on the view engine has the engine name in its name: `project-phtml-provider`, `project-phtml-layout` and `project-phtml-index`, and `project-volt-provider`, `project-volt-layout` and `project-volt-index`.

Volt uses `{{ }}` itself. Thus the placeholders of a Volt view stub are `[[ name ]]`, for example `[[ project ]]` in `project-volt-layout`, and `[[ url ]]` in the views of `make:scaffold` (`scaffold-volt-view-index`, `scaffold-volt-view-new` and `scaffold-volt-view-edit`). Crest replaces only `[[ name ]]` in a `.volt` file, and keeps each `{{ }}` for Volt. The other stubs, also `project-volt-provider`, use `{{ name }}`.

The service of the database and the database lines of `.env` (see [The database](/1.0/creating-a-project#the-database)) come from the project stubs `project-compose-mysql`, `project-compose-mariadb`, `project-compose-pgsql`, `project-env-database` and `project-env-sqlite`. These stubs are the same in both flavors. To change one, for example the image, publish it by name in the folder that the projects go into:

```bash
crest stub:publish project-compose-mysql
```

A copy of a project stub that you published before the database option does not have the new placeholders: `{{ dependsOn }}`, `{{ databaseService }}`, `{{ databaseInstall }}`, `{{ databaseEnv }}`, `{{ databaseIgnore }}`, `{{ phql }}`, `{{ dbUse }}`, `{{ dbProvider }}`, `{{ registerProviders }}` and `{{ models }}`. When the project needs one, `new` stops before it writes a file, and names the copy:

**MVC**

```text
crest: the published stub /path/to/resources/stubs/shared/project-compose.stub has no {{ databaseService }}; publish it again with crest stub:publish project-compose --flavor=mvc --force, and make your changes in it again
```

**ADR**

```text
crest: the published stub /path/to/resources/stubs/shared/project-compose.stub has no {{ databaseService }}; publish it again with crest stub:publish project-compose --flavor=adr --force, and make your changes in it again
```

Without a database, and without `--camel-case` and `--get-set`, such a copy works as before.

The MVC `project-front` also has `{{ viewUse }}`, `{{ viewProvider }}` and `{{ implicitView }}`, and `project-readme` has `{{ viewsRow }}`, for a project with no views. A copy from before them works for a project with views. For `--template-engine=none`, `new` stops on a copy of `project-front` with no `{{ implicitView }}`.

`project-config` has `{{ templateEngine }}`, and `project-composer` has `{{ volt }}`, for a Volt project. A copy from before them works for phtml. For `--template-engine=volt`, `new` stops on a copy of `project-config` with no `{{ templateEngine }}`, and on a copy of `project-composer` with no `{{ volt }}` for `--phalcon=v6`.

Source: https://crest.phalcon.io/1.0/stubs/index.mdx
