Duplicate navigation when using "includes" with Jade/Node - node.js

I have a one page website that I would like to keep but I also need individual sections to be viewed as independent pages. I'm using Jade with Node and everything is working fine until I start including files/blocks.
base.jade
!!! 5
head
body
.nav
// menu
block content
index.jade
extends layout/base
block content
p
| This is the index page.
include about
about.jade
extends layout/base
block content
p
| This is the about page.
What I'm trying to do is use the index page to display all of my pages and then have the individual pages extend the base.jade file. What's happening is I'm getting multiple navigation bars on index.jade because I'm extending base.jade twice. I'm a little stuck and feel like I'm missing something simple here.
Any help is appreciated, thank you.

the file you include should only have the content portion such as
about-content.jade
p
| This is the something about the site.
then index.jade is
extends layout/base
block content
p
| This is the index page.
include about-content
and about.jade
extends layout/base
block content
p
| This is the about page.
include about-content

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.

how to use pug-bootstrap module in nodejs?

I installed the pug-bootstrap module in a nodejs project. I am trying to create a menu from a navbar.
I have done those files:
layout.pug:
include /node_modules/pug-bootstrap/_bootstrap.pug
index.pug:
extends layout
block head
+navbar("menu")
+nav_item("#", undefined, true)
string test
block body
h1= title
p Welcome to #{title}
the _bootstrap.pug contains the bootstrap css file : https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css. But it is not loaded on the webpage.
Someone know why? And how to fix that?
Any help would be appreciate.
When you extend a part of a template with block, you're replacing any code that was already in that block, before. In this case, I assume that the head included a reference to that CSS file, which you're overwriting.
Generally speaking, use append instead of block for the head section (see this page from their docs). That way, previous content of parent templates is not overwritten.
In your usecase, I am doubtful whether you should be placing anything at all in that head block, since it is reserved for meta-tags, not for actual visible content. In other words: You'll need to move the code you have there to the body anyway, since visible document objects belong in the body, not in the head.

"Unexpected identifier" when adding extends/block to wintersmith-jade content file

I am making a static website using Wintersmith alongside the wintersmith-stylus and wintersmith-jade plugins.
I want to add a specific CSS file in a help page. The help page is based off the "layout" template. When I try to use a block to insert the stylesheet into the html head, I receive the following error:
Line ##: Unexpected identifier
layout.jade
doctype html
html
head
block head
link(rel="stylesheet" href="/styles/layout.css")
body
...
help.jade
---
template: layout.jade
---
//- Error inducing code
extends ./layout.jade
block head
link(rel="stylesheet" type="text/css" href="../styles/help.css")
//- end of error inducing code
...
Even if I move the extends and block head lines on top of the metadata block containing template: layout.jade, I still receive the same error. Removing extends ./layout.jade results in the error lines position moving from 40 to 5 in my case.
My guess is the error is caused by the wintersmith-jade plugin, but even if that's the case I'm lost for how I would go about fixing it.
Since I wanted to use both Stylus and Jade (with Jade for both content and templates), I ended up moving over to Harp. Harp not only has Stylus and Jade "built-in", but it's also slightly simpler than Wintersmith.
It's quite a workaround, but I'd say it's actually an upgrade at the same time.
I'm not using wintersmith-jade, but it looks like that plugin shouldn't affect the regular templates in /templates (which is what I think you're referring to).
Looking at templates/article.jade, it looks like you should use just extends layout instead of extends ./layout.jade.
The default templates also do not have the metadata block, but maybe that's necessary for the plugin you're using.

How to divide web pages in blocks with sailsjs

I am starting developing with Sailsjs and I would like to know how to divide a webpage into differents blocks.
for example :
in layout.jade i have
doctype html
html(lang="fr")
head
body
div(class='container')
div(class='row')
div(class='col-md-12')
block header
h1 header
div(class='row')
div(class='col-md-8')
block content
div(class='col-md-4')
block right
block footer
then in my controller1/index.jade i have
extends layout
append content
p
some content
So when I type http://myserver.com/controller1/index in the browser, it works.
How to append some code in the block right form the result of another controller ? (I don't want to append some code to the block right directly in the controller1/index.jade file, to make the file as shorter as possible).
So I guess we can call another method of the controller inside the jade file ?
For example i would like to put a code like :
append right
=call('controller2/action1')
at the end of the controller1/index.jade file.
The purpose of my question is to figure out how divide the html parts of a webpage like we can do it with php using include method (for example).
Thank you
Benjamin

Resources