Abe
Abe

Reputation: 1415

cakePhp - Access folder content inside webroot

This is my desired structure:

-webroot/
    -css/
    -font/
    -img/
    -js/
    -new_folder/
        -file.css
        -another_new_folder/
             -file.js

How can i access webroot/new_folder/file.css and webroot/new_folder/another_new_folder/file.js inside a .ctp file, in order to generate both tags like this:

<link href="/new_folder/file.css">
<script src="/new_folder/another_new_folder/file.js">

without generating controllers, if possible.

Thank you guys.

Upvotes: 2

Views: 1563

Answers (2)

Ajay Krishna Dutta
Ajay Krishna Dutta

Reputation: 770

css:

<?php echo $this -> Html -> css(array('/new_folder/file.css'));?>

js:

<?php echo $this -> Html -> script(array('/new_folder/another_new_folder/file.js'));?>

Upvotes: 0

tarikul05
tarikul05

Reputation: 1913

You can use

echo $this->Html->css('/new_folder/file');
    // webroot/new_folder/file.css
echo $this->Html->script('/new_folder/another_new_folder/file');
    // webroot/new_folder/another_new_folder/file.js

For css and script you can use following way

echo $this->Html->script('custom');
    // webroot/js/custom.js

echo $this->Html->script('otherdir/custom');
    // webroot/js/otherdir/custom.js


echo $this->Html->script('/otherdir/custom');
// webroot/otherdir/custom.js

For more please check Linking to Javascript Files and Linking to CSS Files

Upvotes: 3

Related Questions