【问题标题】:Use Include *pug for subdirectories对子目录使用 Include *pug
【发布时间】:2023-04-08 22:34:02
【问题描述】:

我有这样的文件 head.pug

head
  h2 
    a(href="") This is title

我的目录是:

contact
  + index.pug
pug
  + head.pug
index.pug

在我的主页和联系人中,我使用index.pug,我可以像这样包含head.pug

include pug/head.pug
and
include ../pug/head.pug

它会打印 HTML

 <head>
     <h2><a href="">This is title</a></h2>
 </head>

但在联系人目录中,它应该使用这样的链接打印

 <head>
     <h2><a href="../">This is title</a></h2>
 </head>

我该怎么办?

【问题讨论】:

  • 您是否尝试过在 include 周围加上单引号?包括“../pug/head.pug”?

标签: html pug


【解决方案1】:

您可以在href 中使用正斜杠/。就您而言,这应该适用于链接到主页。

例子:

head h2 a(href="/") This is title

<head> <h2><a href="/">This is title</a></h2> </head>

对于非主页链接,我建议你为你的根目录保留一个全局变量,并存储你要链接的文档的绝对路径。

示例:var TITLE_PATH = &lt;project url here &gt;+'public/someFolder/index.html';

那么,你的 PUG 代码就变成了

head h2 a(href=TITLE_PATH) This is title

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    相关资源
    最近更新 更多