2

What is the correct syntax for including an external js and external CSS file in CakePHP so that these files are included in the <head> from within a view?

By external I mean something like "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css" but I want to place it conditionally in a single view.

1
  • Google searching always produce more tricks than answers along with conflicting info and the documentation doesn't help unless you know the exact helpers involved and since stuff has been deprectated it's even more difficult. Commented Nov 22, 2010 at 4:06

2 Answers 2

4

The answer from xiaohouzi79 is correct for Cake 1.2, but the JavaScript helper has been deprecated in Cake 1.3 (documentation).

CSS (documentation):

$html->css(array('http://example.com/type.css', 'http://example.com/color.css'), null, array('inline' => false));

JavaScript (documentation):

$html->script(array('http://example.com/script.js'), array('inline' => false));

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

4 Comments

Would be nice if the documentation mentioned this on the methods page also book.cakephp.org/view/1451/Methods. Thanks for your answer.
Yes, the documentation could definitely use some work. Glad to help.
Didn't format my question properly, I wanted these to appear in the head. For the benefit of others these two function calls need to include , false, array('inline' => false)); at the end to appear in the head.
Correct. I've updated the code to match your clarified question.
0

For css use the following:

$html->css('http://code.google.com/apis/maps/documentation/javascript/examples/standard.css', false, array('inline' => false)); 

For a javascript file use the following:

$javascript->link('http://maps.google.com/maps/api/js?sensor=false', false); 

btw. don't forget to include the javascript helper in the model.

1 Comment

This is too painful, learning curve shouldn't be related to how easily you can memorise inconsistencies in a language/framework whatever. Every time I go back to Cake I get stung by sh.. like this.

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.