Thread tagged as: Question

Parsing CSS as PHP with perch success (of sorts)

Good news, I managed to achieve what I was trying in this thread:

I simply created a .htaccess file in my /css folder:

AddType application/x-httpd-php .php .css
AddHandler php-script .css

<FilesMatch "\.css$">
  SetHandler application/x-httpd-php
  Header set Content-type "text/css"

Then in my .css files, I have the following:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');?>
<?php header("Content-type: text/css; charset: UTF-8");?>
<?php perch_content_create('css_content',array('template'=>'_css_content.html'));?>
<?php perch_content_custom('css_content');?>

I navigate to the page and enter css information in the css_content region in Perch and voila and it works! No need to change the file extension.

The only "issue" is, Perch places the CSS information in <pre></pre> tags:

<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"></pre></body></html>

So is there any reason why that is the case, and is there any way to output plain text?

Garth Holmes

Garth Holmes 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

What is in your template _css_content.html?

Hi Rachel,

This is my .html template:

<perch:content id="cssinfo" type="textarea" label="CSS text"/>

I tried to add striptags="true" but to no effect

Thank you

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think that's coming from Perch. How are you viewing this?

Hi Drew,

I am viewing the HTML via the Inspector in Chrome.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Try View Source, web inspector is showing you the DOM which is different.