Huy Nguyen Huy Nguyen - 4 months ago 26
Jade Question

Jade Template - Use URL as link label

I have an issue when I add a link inside a paragraph.

The jade template syntax:

p Here is link to #[a(href='https://google.com/') google link]


The result is: Here is link to google link

What I want is: Here is link to https://google.com/

I tried this syntax but it does not work:

p Here is link to #[a(href='https://google.com/') https://google.com/]


An error happen if the link display has
http://
or
https://
.

Thanks for your help!

Answer

It seems you can use a markdown filter to write your link inside the paragraph:

p
  | Here is link to  
  a(href='https://google.com/') https://google.com/

EDIT 1

It also can be done using locals..

{
    URL: 'https://google.com/'
}

..and interpolation:

p Here is link to #[a(href='#{URL}') #{URL}]

EDIT 2

If single quotes are not hindrance, just do:

p Here is link to #[a(href='https://google.com/') 'https://google.com/']

EDIT 3

It's exactly the same as the EDIT 1 but without locals:

p Here is link to #[a(href='https://google.com/') #{'https://google.com/'}]