1

I have, more or less, have these structure

templates
    test.group
       index.html
       another-file.html
       assets
           styles
              foo.css
           scripts   
              bar.js     

As you can see, I put some Javascript and CSS files into a template folder in JS.

I have reasons for this so let's say this is our goal.

I need to include foo.css and bar.css. To access it, I tried

<link href="{site_url}index.php/test/assets/styles/foo.css" rel="stylesheet" type="text/css" />

<script src="{site_url}index.php/test/assets/scripts/bar.js" type="text/javascript"></script>

But this does not work. What I saw was the contents of index.html.

Which is the correct result if you follow EEs template structure.

But I want to bypass this. I want to be able to access the css and js file.

Is there a way to do this?

2

So far as I know, you can't use nested folders on template groups.

Try this:

templates
    test.group
       index.html
       another-file.html
    styles.group
        foo.css
    scripts.group
        bar.js

Or, if you templates are on or below the site root, you can try this, what isn't a good idea:

<link href="{site_url}/themes/site_themes/default/test.group/assets/styles/foo.css" rel="stylesheet" type="text/css" />

<script src="{site_url}/themes/site_themes/default/test.group/assets/scripts/bar.js" type="text/javascript"></script>

Or this, if your {site_url} doesn't have a trailing /.

<link href="{site_url}themes/site_themes/default/test.group/assets/styles/foo.css" rel="stylesheet" type="text/css" />

<script src="{site_url}themes/site_themes/default/test.group/assets/scripts/bar.js" type="text/javascript"></script>

By this way, depending on your server setup, anybody can find your other templates and see them.

0

Normally I keep my CSS and JS files outside of templates in an assets directory inside of the site's document root. Though EE supports using templates for CSS and JS, I've found it's rarely necessary to use them in that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.