Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 548
sheidaei Avatar asked Jan 04 '23 19:01

sheidaei


1 Answers

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>
like image 106
Sunshine Avatar answered Jan 07 '23 09:01

Sunshine