SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Where do I save my css files when using layouts?

    Hello,

    I have been reading about using layouts and have created a helloworld-layout.rhtml file in my layouts directory. Works nicely.

    However, I tried sticking the CSS file in the same directory and referencing it as thus:

    Code:
    <link href="helloworld-layout.css" rel="stylesheet" type="text/css"/>
    When I load the page it doesn't pull over the CSS. I tried a few other references in case I needed to put the full path, etc, but no luck.

    Am I doing something wrong?

  2. #2
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I may have answered my own question...

    I started following a tutorial it took me ages to find. (won't let me link to it)

    It said I should put this bit of code where I would ordinarily reference the stylesheet. e.g:

    Code:
    <title>Library Info System</title>
    <%= stylesheet_link_tag "style" %>
    </head>
    In my case it was:
    Code:
    <%= stylesheet_link_tag "helloworld-layout.css" %>
    So I did this and then moved my stylesheet to /public/stylesheets/ instead of in the same directory as the layout file.

    Huzzah... It worked!

    Sorry to have wasted anybody's time, but who knows, somebody else might find this useful.

  3. #3
    SitePoint Enthusiast davidklaw's Avatar
    Join Date
    Jul 2004
    Location
    Detroit
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is exactly what you want to do, however, you can omit the .css from the filename. It makes it look slightly cleaner

    The first example in your original post would have added a stylesheet include for public/stylesheets/style.css.
    David K.

  4. #4
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to carry the idea a bit further:

    When you have stylesheets that apply specifically to pages served through a particular layout, and no other, you can use the content_for mechanism to see they are included. For example, let's say you want some special editor styles applied whenever you have an in-line editor applied to a form. Put:

    Code:
    <&#37;= yield :editor %>
    in the layout file, then in every view file that you'll need the editor styles place:

    Code:
    <% content_for :editor do -%>
    	<%= stylesheet_link_tag "editor.css" %>
    <% end -%>
    and the "editor.css" file will only be included for those pages.

  5. #5
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tips. Appreciate that very much.

    Also, I just wanted to note in case any complete noobs like me are searching for an answer: it's OK to put stylesheets in a subdirectory of /public/stylesheets

    I have had to create a directory for my own stylesheets and one for those needed by jQuery. I tried Googling to see if that was possible before giving it up and just trying it. So long as you remember to use the path in your tag you're fine. i.e. <&#37;= stylesheet_link_tag "selfmade/helloworld-layout.css" %>

    Unless you guys know of a better method for keeping stylesheets organised?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •