Setting arbitrary PHP constants in index.php I was looking for a way to set arbitrary PHP constants in the index.php that could then be accessed within templates.

This is particularly useful if you have more than one index/domain pulling content from a core Craft install as the additional domains won't have any configuration files to use, just index.php.
Hat-tip to Brad for finding this answer.

This can be achieved with something like the following in your index.php:

define('BRADS_FAVORITE_HOBBY', "Drinking");


Thanks to the power to Twig, you can then access this in your templates using:

{{ constant('BRADS_FAVORITE_HOBBY') }}