Displaying an Image in Jade

So I have the following Jade code h3(class="text-muted") MedKit that displays the word "MedKit" at the top of a web page and right next to it I want to display an image. How would I go about doing this and how should I upload/save the image I want to display?

2

2 Answers

You can display a image by using the img tag. In jade the syntax looks like:

img.className#IdName(src="/path-to-image.jpg" alt="Image Title")

To display it next to your h3 tag:

.image-block
  h3 Hello
  img.className#IdName(src="/path-to-image.jpg" alt="Image Title")

I suggest you read about piping in jade too. Just ensure that you replace the spaces with tabs else it will give a compilation error.

Pug code to display image from db is...

img.image(src='/' + img_path_var )

old jade code

img.image(src='/#{img_path_var}')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest