0

Could someone please advise me on the current methods available for using PHP in a CSS file in CakePHP 2.x

I have currently separated my stylesheet into a php file and wish to parse my data via the URL but I cannot seem to work out how to link it using

$this->Html->css('dynamic-stylesheet')  

as it always appends .css to the name.

Your help is much appreciated.

2 Answers 2

3

You can generate the tag by using HtmlHelper::meta()

echo $this->Html->meta(array(
    'link' => '/css/test.php',
    'rel' => 'stylesheet',
    'type' => 'text/css'
));

Note that you need to explicitly direct it to the /css directory, as you are no longer using a helper method specifically for CSS.

Sign up to request clarification or add additional context in comments.

Comments

1

Looking at the Html helper file in the CakePHP library located at lib/Cake/View/Helper/HtmlHelper.php, check out line 427, looks like the .css extension is set automatically unless there are two slashes in the CSS file name. I GUESS that is to catch external resources?

From the aforementioned library file:

if (strpos($path, '//') !== false) {
    $url = $path;
} else {
    $url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css'));

    if (Configure::read('Asset.filter.css')) {
        $pos = strpos($url, CSS_URL);
        if ($pos !== false) {
            $url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
        }
    }
}

So this..

echo $this->Html->css('http://whatever.com/css/dynamic-stylesheet.php');

Would render the dynamic-stylesheet.php file rather than defaulting to 'dynamic-stylesheet.css.

Not sure that is what this was intended for but maybe that file will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.