I'm a newbie to Craft and am working with a raw version of Craft CMS 2.6.2903 on localhost and am trying to understand some of the basics. The problem that I am encountering at the moment is to do with the Twig includeCssFile command.
I want to create a folder that will contain all my CSS details, so I went to _layout.html and moved all the CSS script from between the style tags into a new script which I saved at craft/templates/styles/index.css. I then deleted the style tags from _layout.html.
I added this line to the <head> section of the _layout.html script:
{% includeCssFile "styles/index.css" %}
So that the <head> section looked like this:
<head>
<meta charset="utf-8" />
<title>{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}< /title>
<link rel="home" href="{{ siteUrl }}" />
{% includeCssFile "styles/index.css" %}
</head>
and once again the Home page worked perfectly.
The problem occurred after I moved the whole styles folder up one level (i.e. to the same level as the templates folder).
I changed the calling code to {% includeCssFile "../styles/index.css" %} and refreshed the home page and had lost all the page styling. I played around with removing the '../' and changing it to './' and even '/' but it still didn't work. When I returned the styles folder to the templates folder, it all worked okay again.
There have been a couple of similar questions already posted on this group, but they haven't resolved my problem (link 1, link 2)
Can someone please tell me what I need to do?
{% includeCssFile "public/styles/index.css" %}
to 'call' it.
Worked like a charm.
Thanks also for the 'inlin' plugin info as well.
– Crafty Cockney Aug 14 '16 at 14:47includeCssFileto add an external stylesheet to your markup – a plain old, hard coded<link>tag will do just fine (one of the best things about Craft is that it makes no assumptions about your front end). The primary use case forincludeCssFileis when you want to include a CSS file from inside a{% block %}tag or an included template partial. – Mats Mikkel Rummelhoff Aug 14 '16 at 18:21The only problem I have with accessing the CSS code via the 'new' method is that when I do a 'Live Preview' within 'Entries', all the CSS code is lost. When I hard-code the CSS code into '_layout.html' (as per original setting), the 'Live Preview' works fine. However, when I use a full URL like this
– Crafty Cockney Aug 15 '16 at 00:45{% includeCssFile http://localhost/sitename/assets/styles/index.css %}the Live Preview works fine.<link rel="stylesheet" href="{{ siteUrl }}assets/styles/index.css">. However, I cannot get it to work in conjunction with theincludeCssFilecommand. – Crafty Cockney Aug 15 '16 at 01:47{% includeCssFile siteUrl ~ "assets/styles/index.css" %}– GlabbichRulz Mar 30 '18 at 14:20