admin管理员组

文章数量:1419191

I have the following Pug snippet and I'm trying to show a URL inside one of the td tags. However, when I run this the resulting output is displaying a(href=val.url+'/update') followed by the correct #{val.name}. How do I go about telling Pug that the value inside the td tag is a link and that #{val.name} should be the hyperlink? If I remove the table and display the href tag inside a p tag it works fine.

extends layout

block content
  h1= title

  table.table.table-condensed
    thead
      tr
        th Name
        th Date Created
        th Date Modified
        th Ready for Hire
      tbody
      each val in list_genres
        tr
          td a(href=val.url+'/update') #{val.name}
          td #{val.date_created}
          td #{val.date_created}
          td No
      else
        li There are no candidates.

I have the following Pug snippet and I'm trying to show a URL inside one of the td tags. However, when I run this the resulting output is displaying a(href=val.url+'/update') followed by the correct #{val.name}. How do I go about telling Pug that the value inside the td tag is a link and that #{val.name} should be the hyperlink? If I remove the table and display the href tag inside a p tag it works fine.

extends layout

block content
  h1= title

  table.table.table-condensed
    thead
      tr
        th Name
        th Date Created
        th Date Modified
        th Ready for Hire
      tbody
      each val in list_genres
        tr
          td a(href=val.url+'/update') #{val.name}
          td #{val.date_created}
          td #{val.date_created}
          td No
      else
        li There are no candidates.
Share Improve this question asked Sep 13, 2017 at 16:18 Matthew SnellMatthew Snell 9573 gold badges12 silver badges27 bronze badges 2
  • Have you tried to put the a-element on a new line below, with an extra indent? AFAIK, Pug interprets any code that directly follows a tag on the same line as text. – gandreadis Commented Sep 13, 2017 at 18:46
  • 1 Brilliant! That makes sense now that I've seen p tags written with text on the new line. – Matthew Snell Commented Sep 13, 2017 at 18:54
Add a ment  | 

1 Answer 1

Reset to default 7

Thanks to @gandreadis, the solution is below. Any text seen after recognized code (in this case td) is interpreted as text only. A new line is needed.

extends layout

block content
  h1= title

  table.table.table-condensed
    thead
      tr
        th Name
        th Date Created
        th Date Modified
        th Ready for Hire
      tbody
      each val in list_genres
        tr
          td 
            a(href=val.url+'/update') #{val.name}
          td #{val.date_created}
          td #{val.date_created}
          td No
      else
        li There are no candidates.

本文标签: javascriptDisplaying URL inside table tdPugJadecurrently only displaying as textStack Overflow