index.jade not showing up any content - node.js

I screenshot the code to show the code indent. Previously I had error displaying on index.hade so, I remove the indent and the error gone. I did the same for layout.jade but the header went missing. SO I just leave it with indentation. But I've no clue as to why the contents of index.jade not showing up at all and not even error to denote?
layout.jade
index.jade
This is how it appears on web without textbox and button.

I think your indentation might be a bit off. Try copy and pasting the following:
layout.jade
doctype html
html
block head
title title
link(href='/stylesheets/style.css' rel='stylesheet' type='text/css')
body
header#banner
h1 Awesome Chat
block content
footer Hope you enjoy your stay here
index.jade
extends ./layout
block content
section#chatroom
div#messages
input#message(type="text" placeholder="Enter your message here")
input#send(type="button" value="Send")

Related

Express 4+pug disable layout

I want to ajax for blocks that without layout
Such as
extends layout
block content
p xxxx
I want to get the content in block
if !layout
include layout
The solution
If you don't want the standard pug layout then create a file that doesn't have extends layout in it:
doctype html
html(lang='en-us')
head
title Page Title
body
div Content goes here
You don't need to do anything in your app.js file to make this happen. You've probably figured out that none of the statements in your question work. This is all controlled in the pug template file.

I am extending a pug layout(parent) to another pug layout(child).I am getting an error 'unexpected token:indent' from the parent layout

This file name is layout.pug(parent):
doctype html
html
head
title knowledgebase
body
block content
br
hr
footer
p Copyright © 2018
And this file name is index.pug(child):
extends layout
block content
h1 articles
h1 #{title}
At first I thought everything was good with your code, then I looked closely at what was pasted here.
If inspect the code in layout.pug you'll see that there's a leading space on every line. Make sure that doctype html and html (which are your root elements in the parent template) have ZERO spaces at the start of the line.
Otherwise your code looks good and should work as expected.

jade extends layout and if statement

hi and sorry for my english.
I've a very simple "layout.jade"
!!! 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
and a very simple "index.jade"
extends layout
block content
- if (session) {
p Welcome
- } else {
p Login
-}
With this code i've got a blank page.
Now if i remove extends layout from my "index.jade" and i put the code directly in "index.jade" everything works fine, that is to say my conditional statement give me <p>Welcome</p> or <p>Login</p> no blank page any more.
I'm new to nodejs and my problem may be evident for many of you ;)
Thanks!
It looks like you have a leading whitespace mismatch, which is a no-no in significant whitespace languages like jade. Also if and else are directly supported in jade:
extends layout
block content
if session
p Welcome
else
p Login

how to render multiple jade templates

I am trying to understand how JADE works when there are several templates.
I worked by this tutorial:
http://www.franz-enzenhofer.com/jade
But, I got this:
$ curl http://localhost:3000
<h1> Franz Enzenhofer</h1>
It seems that the command "res.render('index.jade',..." only took the index.jade template, but didn't insert it into the layout.jade template as should happen...
I assume you are using partials. They were removed with express v3. See the View System Changes part for more information.
From express v3 on you should use blocks. For example:
my-template.jade:
extends my-layout
block head
script(src="myfile.js")
block content
h1 My page
my-layout.jade
doctype 5
html
head
title My title
block head
body
#content
block content

How to embed content in jade

I'm currently experimenting with jade template engine. I've got the follow basic code in my layout.jade file:
!!! 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body!= body
header != partial('partials/head')
'dependant page content to go here'
footer != partial('partials/foot')
I'd like every page to follow this same structure (for now). However I would like the content to change, and the content should be depended on what is inside the 'pagename'.jade files e.g. index.jade:
section#page-content
h1= title
p Welcome to #{title}
What i'm trying to say is, upon a new page loading.. the content tag in layout should somehow be replaced by the appropriate tag of the page being loaded.
I think you're looking for:
body
header
p my header
section!= body
footer
p my footer
In this case, section!= body is replaced by whatever is in the 'pagename'.jade files.
use blocks
in layout.jade:
body
block some-block
p Blah
in test.jade
extends layaout
block some-block
p What

Resources