title: Using css variables with php in joomla 3 template
body: <p>My idea is to use template parameter in joomla to set the color for a background, text or buttons.
  I want to define a css class instead of each time using style=&quot;background-color:<code>&lt;?php echo $buttoncolor ?&gt;</code>;&quot; as I don't want to write countless template overrides.</p>
  <p>I believe that could be very usefull feature.</p>
  <p>The parameter in my templateDetails.xml looks like</p>
  <pre><code>&lt;field name=&quot;buttoncolor&quot; type=&quot;color&quot; default=&quot;#309000&quot;
                      label=&quot;TPL_BUTTON_COLOR_LABEL&quot;
                      description=&quot;TPL_BUTTON_COLOR_DESC&quot; /&gt;
  </code></pre>
  <p>The idea how to use php variable in css I found on <a href="http://css-tricks.com/css-variables-with-php/" rel="nofollow noreferrer"> CSS-Tricks</a></p>
  <p>To use a php variable within a css I linked to this file in my index.php</p>
  <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo $this-&gt;baseurl ?&gt;/templates/&lt;?php echo $this-&gt;template; ?&gt;/css/style.php&quot; type=&quot;text/css&quot;  /&gt;
  </code></pre>
  <p>My style.php looks like:</p>
  <pre><code>&lt;?php 
  header(&quot;Content-type: text/css; charset: UTF-8&quot;);
  $buttoncolor = $this-&gt;params-&gt;get(&quot;buttoncolor&quot;);
  ?&gt;
  
  .buttoncolor {background-color: &lt;?php echo $this-&gt;params-&gt;get('buttoncolor'); ?&gt;;}
  </code></pre>
  <p>Usally I set a variable to a template parameter in the index.php like</p>
  <pre><code>&lt;?php 
  //parameter
  $app = JFactory::getApplication();
  $doc = JFactory::getDocument(); 
  $params = $app-&gt;getParams();
  $buttoncolor = $this-&gt;params-&gt;get('buttoncolor'); 
  ?&gt;
  </code></pre>
  <p>Unfortunately I got the following error:
  Fatal error:  Using $this when not in object context in style.php</p>
  <p>Any ideas, workaround and help is highly appreciated!</p>