简体   繁体   English

SASS和Liferay - 如何在自定义主题中使用?

[英]SASS and Liferay - how to use in custom themes?

I don't really find an answer on liferay's blogs and google - so i hope anyone here can help me. 我真的没有在liferay的博客和谷歌上找到答案 - 所以我希望这里有人可以帮助我。

I'm trying to get started with sass in a custom theme i am building in liferay 6.2. 我正在尝试使用我在Liferay 6.2中构建的自定义主题开始使用sass。

As i understand it, the approach would be this: 据我了解,方法是这样的:

  1. create an empty theme, (using maven,) based off _styled 创建一个空主题(使用maven),基于_styled
  2. this gives me a file layout like this: 这给了我一个像这样的文件布局:

     <theme> +-src +-main +-webapp +-css +- ... here i'll put any css overwrites 
  3. develop sass stylesheets, link to main.css 开发sass样式表,链接到main.css

     <theme> +-src +-main +-webapp +-css +-main.css +-custom.scss 

main.css initially looks like this: main.css最初看起来像这样:

@import url(custom.css);

/* other css import here */

custom.scss would contain some SASS content: custom.scss将包含一些SASS内容:

$color: #f00;
body {
    color: $color;
}

Now my question: How do I link both CSS and SASS together correctly? 现在我的问题是:如何正确地将CSS和SASS链接在一起? How does the @import statement in main.css have to be defined? 如何定义main.css中的@import语句?

I tried @import url(custom.scss); 我试过@import url(custom.scss); but this won't give me the desired results. 但这不会给我预期的结果。 Likewise, @import url(custom.css); 同样,@ @import url(custom.css); won't do it either. 也不会这样做。

I found the solution. 我找到了解决方案。 Key is to understand that Liferay does not use the file extension *.scss on a theme's stylesheets. 关键是要了解Liferay不在主题的样式表上使用文件扩展名*.scss Just dropping my SASS code into a *.css file did the job! 只需将我的SASS代码放入*.css文件即可完成工作!

Found the solution here . 这里找到解决方案。

My directory layout: 我的目录布局:

<theme>
  +-src
     +-main
        +-webapp
           +-css
              +-main.css
              +-custom.css

main.css looks like: main.css看起来像:

@import url(custom.css);

/* other css import here */

and custom.css like this: custom.css像这样:

$color: #f00;
body {
    color: $color;
}

And the result is (in custom.css , after reloading on the web browser): 结果是(在custom.css中 ,在Web浏览器上重新加载后):

body {
    color: #f00;
}

Hooray! 万岁!

是的,如果您在Liferay 6.2中工作,文件扩展名应为.css,但如果您在Liferay 7 / DXP中工作则应该是.scss。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM