Answers.Body: <p><em>Hat-tip to Brad for finding this answer.</em></p>
  
  <p>This can be achieved with something like the following in your index.php:</p>
  
  <pre><code>define('BRADS_FAVORITE_HOBBY', "Drinking");
  </code></pre>
  
  <p>Thanks to the <a href="http://twig.sensiolabs.org/doc/functions/constant.html" rel="noreferrer">power to Twig</a>, you can then access this in your templates using:</p>
  
  <pre><code>{{ constant('BRADS_FAVORITE_HOBBY') }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-18T10:48:58.967Z
Answers.Text: Very useful in certain cases, indeed. Thanks for sharing, Steve.
Answers.UserDisplayName: Jérôme Coupé
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-18T09:53:31.343Z
Answers.LastActivityDate: 2014-11-18T09:53:31.343Z
Answers.UserDisplayName: Steve Abraham
Body: <p>I was looking for a way to set arbitrary PHP constants in the index.php that could then be accessed within templates.</p>
  
  <p>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.</p>
  
Tags: <variable><php><index>
Title: Setting arbitrary PHP constants in index.php
ThreadText: # Setting arbitrary PHP constants in index.php
  
  (Asked by: username_0 on 2014-11-18)
  
  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.
  
  **Tags:** variable, php, index
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2014-11-18. Score: 5
  
  *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](http://twig.sensiolabs.org/doc/functions/constant.html), you can then access this in your templates using:
  
  ```
  {{ constant('BRADS_FAVORITE_HOBBY') }}
  
  ```
  
  > **Comments:**
  > **username_1**: Very useful in certain cases, indeed. Thanks for sharing, username_0.  
  
  ---
  
  