使用 theme_inject 在指定目录下的所有子目录 html 中嵌入 css #35
-
Please follow this Issue template to provide relevant information, such as source code repository, website URL and screenshots, which will help us investigate. Issue Checklist
Steps to reproduce the behavior目前,我有一个需求:在指定目录下的所有子目录 html 中嵌入 css。 例如:在一级菜单
这可以正常工作。即在 a 页面及其所有子页面中正确嵌入以上 css。 但同时会报以下错误:
抱歉我对 Nunjuck 模板语法不太熟悉,我是否写的不太规范或哪里出错了? Environment InformationNode.js and NPM Information
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details. |
Beta Was this translation helpful? Give feedback.
-
把
改成这样
试试 |
Beta Was this translation helpful? Give feedback.
-
@stevenjoezhang 我试了下,报错如下(而且这样写无法在页面插入 css):
|
Beta Was this translation helpful? Give feedback.
-
好的,我知道原因了。head 注入点在 .sub-menu + .content {
padding-top: 40px;
} 这样就不需要对路径进行判断。 |
Beta Was this translation helpful? Give feedback.
-
@stevenjoezhang 感谢!😀 |
Beta Was this translation helpful? Give feedback.
好的,我知道原因了。head 注入点在
page
变量被赋值前,被 Nunjucks 预处理了,因此导致page.path
为undefined
;如果直接修改layout
目录下的模版就不会有这个问题。这个改起来需要一些时间,不过你的需求其实可以绕开这个问题,那就是用 CSS 的相邻元素选择器
这样就不需要对路径进行判断。