Forum

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:

https://forum.grabaperch.com/forum/09-26-2016-parsing-css-javascript-as-php-and-editing-within-perch

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"
</FilesMatch>

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

https://docs.grabaperch.com/templates/attributes/striptags/

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.