I am doing the Wes-bos Learn node course.I am on the part of saving stores and using mixins. When I write mixins and run my app it gives this error.
Error: C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\views\mixins\_storeForm.pug:1:1
> 1| mixin storeForm(store = {})
-------^
2| form(action="/add" method="POST" enctype = "multipart/form-data" class="card")
3| label(for="name") name
4| input(type="text" name="name")
Mixin storeForm declared without body
at makeError (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-error\index.js:32:13)
at Parser.error (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-parser\index.js:53:15)
at Parser.parseMixin (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-parser\index.js:871:12)
at Parser.parseExpr (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-parser\index.js:204:21)
This is the file in Mixins (_storeForm.pug)
mixin storeForm(store = {})
form(action="/add" method="POST" enctype = "multipart/form-data" class="card")
label(for="name") name
input(type="text" name="name")
This is the file in views folder
extends layout
include mixins/_storeForm
block content
.inner
h2= title
+storeForm({name:'dkjd'})
I am new to nodejs/pug/express. What is wrong with this code. This code in the given video works fine but not on my desktop.
Inside your mixin storeForm, you need to indent form and its children once more. Like so:
mixin storeForm(store = {})
form(action="/add" method="POST" enctype = "multipart/form-data" class="card")
label(for="name") name
input(type="text" name="name")
Related
I am getting this error I am trying to get the href to be /sendnotify/room.roomNumber.
Error: /root/13h31762/views/classmanager.jade:14
12| -var roomurl = "/sendnotify/"+ room.roomNumber;
13| li your Classes --->
> 14| a(href=roomurl, class='roomlink')#{room.roomName}
15|
16|
Unexpected token `interpolation` expected `text`, `code`, `:`, `newline` or `eos`
I have no clue why. My jade view is included below
extends layout
block content
div.container
div.row
div.col-sm-6.col-md-4.col-md-offset-4
#user
h1.text-center.login-title Welcome #{user.firstName}. Check your details below:
div.signup-wall
ul.user-details
each room in user.room
-var roomurl = "/sendnotify/"+ room.roomNumber;
li your Classes --->
a(href=roomurl, class='roomlink')#{room.roomName}
Try adding a space before your variable for roomname:
a(href=roomurl, class='roomlink') #{room.roomName}
Or since you only have the variable in the a-tag you can use:
a(href=roomurl, class='roomlink')= room.roomName
I'm currently working through some Node.js ExpressJS and MongoDB and have hit a snag with the Jade. I keep getting an input is self closing and should not have content error when I go to my newuser page. I've checked everything on this site, been through the jade-lang docs and have come up short, could really use some guidance with this Jade shenanigans. Thanks everyone!!
Here is my code:
extends layout
block content
h1= title
form#formAddUser(name="adduser",method="post",action="/adduser")
input#inputUserName(type="text", placeholder="username", name="username")
input#inputUserEmail(type="text", placeholder="useremail", name="useremail")
button#btnSubmit(type="submit", value="submit")
And here is my error message:
/home/evan/dev/nodetest1/views/newuser.jade:7 5| //- h1= title 6| form#formAddUser(name="adduser",method="post",action="/adduser") > 7| input#inputUserName(type="text", placeholder="username", name="username") 8| input#inputUserEmail(type="text", placeholder="useremail", name="useremail") 9| button#btnSubmit(type="submit", value="submit") 10| input is self closing and should not have content.
The error says exactly what the problem is, but unless you know how to translate it, that doesn't mean it's easy to understand :D
input#inputUserName(type="text", placeholder="username", name="username")
input#inputUserEmail(type="text", placeholder="useremail", name="useremail")
button#btnSubmit(type="submit", value="submit")
will try to put #inputUserEmail inside #inputUserName and #btnSubmit inside #inputUserEmail because of the indentation. It should just be
input#inputUserName(type="text", placeholder="username", name="username")
input#inputUserEmail(type="text", placeholder="useremail", name="useremail")
button#btnSubmit(type="submit", value="submit")
This is because in HTML, <input> elements do not have children, so the nesting is not allowed.
Running through this useful walkthrough for Node.js authentication with Passport, but utilising Jade templating rather than ejs. When actually running the app, the correct values are displayed in the HTML, but it annoys me that command-line jade complains. Any ideas why?
Here is the calling code:
exports.myAccount = function (req, res) {
res.render('myAccount', {
title: 'Welcome back.',
user: req.user
})
};
... and a snippet of the Jade file (myAccount.jade) :
div.row
div.col-sm-6
div.well
h3
span(class="fa fa-user")
| Local
p
strong id
| : #{user._id}
br
strong Username
| : #{user.local.username}
Finally, the error when running Jade is:
TypeError: myAccount.jade:22
20| p
21| strong id
> 22| | : #{user._id}
23| br
24| strong Username
25| | : #{user.local.username}
Cannot read property '_id' of undefined
at eval (eval at <anonymous> (..../lib/jade.js:172:8), <anonymous>:138:49)
As already mentioned, the values do actually render, so how do I get Jade to quit complaining??
adv-THANKS-ance
The short answer: provide some data on the command line so jade can properly render your string interpolation expressions such as #{user._id}.
jade --obj '{"user": {"_id": "42", "local": {"username": "bob"}}}' myAccount.jade
Explanation: Jade takes 2 things as input: some jade syntax plus some data. In your app, the data is provided by your code taking req.user, etc, so jade has what it needs to render the template to HTML. On the command line, there's no data there, so you have to provide it as I've done above.
Bonus Tip: There's more concise ways to express your template without so many pipes:
div.row
div.col-sm-6
div.well
h3
span.fa.fa-user Local
p
strong= "id: #{user._id}"
br
strong= "Username: #{user.local.username}"
This is my configuration file.
docpadConfig = {
templateData:
site:
title: 'hello docpad'
getTitle: ->
#site.title
getString: ->
'just a string'
}
# Export the DocPad Configuration
module.exports = docpadConfig
From a jade layout when I do title= site.title it renders ok. When I try to call the helper function title= getTitle() the console outputs this:
error: An error occured:
ReferenceError: /Volumes/Data/project/am/lab/docpad/hello_docpad/src/layouts/default.html.jade:21
19|
20| //- Our site title and description
> 21| title= getTitle()
22|
23| //- Output DocPad produced meta elements
24| != getBlock('meta').toHTML()
site is not defined
at docpadConfig.templateData.getWat (/Volumes/Data/project/am/lab/docpad/hello_docpad/docpad.coffee:10:16)
at eval (eval at <anonymous> (/Volumes/Data/project/am/lab/docpad/hello_docpad/node_modules/docpad-plugin-jade/node_modules/jade/lib/jade.js:170:8), <anonymous>:47:64)
Looks like I can't access the site object from inside the helper function.
I'm sure I'm missing something trivial, maybe a plugin is needed for this... can't find out "wat" is wrong here.
I've found the solution looking into a similar issue in a docpad skeleton. This relates to a bug in the Jade pre-processor.
Update to "docpad-plugin-jade": "~2.4.1" fixes the issue.
i am using backbonejs with node js trying to pass variable from backbone view to template(html file). function for rendering view template is like this :
render: function(event){
var compiled_template = _.template( $("#results-template").html() );
console.log(myPhoto.toJSON());
$(this.el).html(compiled_template(myPhoto.toJSON()));
return this;
}
myPhoto having a value :
{
src: 'placeholder.jpg',
title: 'an image placeholder',
coordinates: [0,0],
tags: ['untagged'],
location: 'home'
}
and in html file :
<script id="results-template" type="text/template">
<h2><%= title %></h2>
<p>testing....</p>
</script>
when i am execute it gives an error like
ReferenceError: c:\trello\testApp/views/test.html:19
17| <script id="results-template" type="text/template">
18|
>> 19| <h2><%= title %></h2>
20| <p>testing....</p>
21| </script>
22|
title is not defined
at Object.<anonymous> (eval at <anonymous> (c:\trello\node_modules\ejs\lib\ejs.js:203:1))
at Object.<anonymous> (c:\trello\node_modules\ejs\lib\ejs.js:201:15)
at ServerResponse._render (c:\trello\node_modules\express\lib\view.js:425:21)
at ServerResponse.render (c:\trello\node_modules\express\lib\view.js:318:17)
at c:\trello\testApp\test.js:23:16
at callbacks (c:\trello\node_modules\express\lib\router\index.js:272:11)
at param (c:\trello\node_modules\express\lib\router\index.js:246:11)
at pass (c:\trello\node_modules\express\lib\router\index.js:253:5)
at Router._dispatch (c:\trello\node_modules\express\lib\router\index.js:280:4)
at Object.handle (c:\trello\node_modules\express\lib\router\index.js:45:10)
how to solve this???
Are you sure all your photos have a title? Empty properties can cause this error. You can fix this by adding default values (empty strings for example) in your backbone Model class.