Shopify themes, liquid, logos, and UX
Hi,
How to import an additional CSS file in theme.liquid?
I'm guessing it would be in this section:
"<script>
var theme = {
stylesheet: "{{ 'theme.scss.css' | asset_url }}",
"
what would the proper syntax be to add another stylesheet (not replacing the one that is already listed)?
Thanks
Solved! Go to the solution
This is an accepted solution.
No problem, happy to provide as much clarification as you need.
So, I wouldn't RENAME any sheet. You don't want to break anything that is currently working on your site. If you're talking about importing a NEW sheet, you want to create a new Asset file (scss.css.liquid file in the Assets folder of your theme).
When you creat the file, the window has you type in the file name & auto-populates the suffix by what you select from the dropdown. So lets say you select 'scss.css.liquid' & in the text field you type 'rikdev'.
The file you just created is called 'rikdev.scss.css.liquid'. So to get it to load in your theme.liquid file ( meaning across the entire site ) You would include this line.
{{ 'rikdev.scss.css' | asset_url | stylesheet_tag }}
Where you include it is up to you, and how you incorporate web dev practices. More than likely, you DO NOT need it to be at the top of your theme.liquid. You would only need them at the top of Theme.liquid ( like between the <head></head> ) if the styles you are importing are critical (meaning without these, your page looks blank/white/really bad).
As it is a secondary sheet, im going to assume that they are NOT critical. Meaning you can go to the VERY VERY bottom of your Theme.liquid file, and insert that line just above the closing </body> tag. So all in all it will look like this
// .. // Bunch of code from Theme.liquid here {{ 'rikdev.scss.css' | asset_url | stylesheet_tag }} </body>
The code you included appears as if you are possibly trying to lazy load the style sheet? You do not need to do this.
All you need to do is:
{{ 'sheetname.scss.css' | asset_url | stylesheet_tag }}
Thanks... but do you mean simply to rename my css stylesheet to somename.scss.liquid and add the line '
{{ 'sheetname.scss.css' | asset_url | stylesheet_tag }}
' anywhere in the theme.liquid code? I guess I need a little clarification.
Thanks
This is an accepted solution.
No problem, happy to provide as much clarification as you need.
So, I wouldn't RENAME any sheet. You don't want to break anything that is currently working on your site. If you're talking about importing a NEW sheet, you want to create a new Asset file (scss.css.liquid file in the Assets folder of your theme).
When you creat the file, the window has you type in the file name & auto-populates the suffix by what you select from the dropdown. So lets say you select 'scss.css.liquid' & in the text field you type 'rikdev'.
The file you just created is called 'rikdev.scss.css.liquid'. So to get it to load in your theme.liquid file ( meaning across the entire site ) You would include this line.
{{ 'rikdev.scss.css' | asset_url | stylesheet_tag }}
Where you include it is up to you, and how you incorporate web dev practices. More than likely, you DO NOT need it to be at the top of your theme.liquid. You would only need them at the top of Theme.liquid ( like between the <head></head> ) if the styles you are importing are critical (meaning without these, your page looks blank/white/really bad).
As it is a secondary sheet, im going to assume that they are NOT critical. Meaning you can go to the VERY VERY bottom of your Theme.liquid file, and insert that line just above the closing </body> tag. So all in all it will look like this
// .. // Bunch of code from Theme.liquid here {{ 'rikdev.scss.css' | asset_url | stylesheet_tag }} </body>
Thanks for taking the time... worked well!
-R
but, how create a new stylesheet inheriting vars from default stylesheet? no working "@use" or "@import"
How can I include a custom .scss file into the theme.scss.liquid file?
I guess what is the best practice and what is the recommendation by the shopify community for adding custom styles to your app?
Should the styles be added like mentioned above and then imported like so to the theme.liquid file for global custom css styles and then to each seperate .liquid file for modular css changes?
Thanks
PS. Is there a way to do hot module reloading so I dont have to refresh the page each time using theme kit
Thanks
Hi @aquasar,
"How can I include a custom .scss file into the theme.scss.liquid file?"
@import "custom.css";"custom.css" must be created in the same assets/ directory where the theme.scss.liquid is present.
Hope this will help you. I have spend half of a day investigating and searching a solution for that.
BR
Hi @SvilenUkalski We are trying to divide a theme by sections,
EG: divide footer SCSS from header SCSS and like that, we thought about using import in order to use the SCSS variables defined on theme.scss.liquid.
We couldn't do that with ThemeKit, we were watching Grunt but we realized that it seems it has no support anymore.
Is there any other thing we can use?
The reason why we do that is cause we are a team of some people and we are working on one Theme and it is hard to work all at the same time without having issues with theme watch, merge, and that stuff.
Thank you.
Juanse Gimenez
Hi @JuanseGimenez,
I think it will be most helpful for everyone to create/rise new question so my answer will be easy to be found. This one is already solved and not the case of our discussion.
Paste the link for the new question as a comment here so I'll be able to find it.
Thanks!
BR
Svilen
As far as I can tell, this method works but is relatively outdated. I recommend checking out ThemeKit's solution: https://www.shopify.com/partners/blog/live-reload-shopify-sass.
Hi there, thanks for the kind help!
I have tried to use the @import 'custom.css' method in the theme.css.liquid file, but it didn't worked for me.
Is this method still apply?
User | RANK |
---|---|
73 | |
66 | |
56 | |
55 | |
42 |
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023