简体   繁体   中英

Dynamic url for a tag in Pug (Jade) template

I want to dynamically change the URL text. This is the code I am using in my Pug template engine:

html
  head
    title=title
    <link rel="stylesheet" type="text/css" href="/css/style.css">
  body(style={'background-color': color })
    #content 
      .bigquestion=message
      | <div class='questionnumber'>
      a(href=`/question/`+ questionnumber) =questionnumber
      | / 
      =totalnumberofquestions
      | </div>

I am getting the following:

<div class='questionnumber'><a href="/question/98">question =questionnumber</a>98/ 135</div>

I want the output to be something like this:

<div class='questionnumber'><a href="/question/98">question 98</a> / 135</div>

Is there any way that I can use a dynamic text for the URL in Pug templating engine?

I was able to only find static texts examples only here .

Check out this section in the documentation.

https://pugjs.org/language/interpolation.html

html
  head
    title=title
    <link rel="stylesheet" type="text/css" href="/css/style.css">
  body(style={'background-color': color })
    #content 
      .bigquestion=message
      | <div class='questionnumber'>
      a(href=`/question/`+ questionnumber) #{questionnumber}
      | / 
      =totalnumberofquestions
      | </div>

您需要在变量上使用插值,例如#{questionnumber}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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