Learn how to create a custom DDEV command that opens your Craft CMS Control Panel at the correct URL, even when you've customized the cpTrigger.
Craft 5
Here are a few helpful details on the code that I didn’t cover in the video. Consider this some extra credit!
The comments at the top of the file have a purpose: to inform the developer and provide content to the help output.
#!/usr/bin/env bash # Portable shebang - finds bash anywhere
## Description: Launch Craft CMS Control Panel (reads CRAFT_CP_TRIGGER from .env)
## Usage: launch-cp
## Example: "ddev launch-cp"
#!/usr/bin/env bash
is more portable than #!/bin/bash
ddev help
outputFind lines starting with CRAFT_CP_TRIGGER=
in the .env
file:
grep "^CRAFT_CP_TRIGGER=" .env
Get only what comes after the =
sign:
cut -d'=' -f2
And then remove any quotes, just so you have the value of CRAFT_CP_TRIGGER
:
tr -d '"' | tr -d "'"
DDEV_HOSTNAME
is automatically provided by DDEV and there are other DDEV-provided environment variables available to use in a custom command.