Ad
Duplicates When Iterating Loop In Jade
I have an array, globally defined in my Node.js app index, app.js like
posts = [];
this array is filled with blocks of html, and if I loop the array in my index, I get the following (currently only filled with one block)
for(var i in posts) console.log(posts[i]);
<h1 id="this-is-ma-title">this is ma title</h1>
<p>hello <strong>123</strong></p>
this is the expected result. When I try to print out this array in the view model however, like this
extends layout
block content
.post
#{posts}
the content seems to duplicate, and also contains random < > notation in the client browser
<div class="post"><<h1 id="this-is-ma-title">this is ma title</h1>
<p>hello <strong>123</strong></p>
></<h1 id="this-is-ma-title">this is ma title</h1>
<p>hello <strong>123</strong></p>
></div>
I have tried various differentiations of the loop notation, like
each item in posts
item
and
- for (var i=0; i<posts.length; i++) {
.post
#{posts[i]
- }
but all produce similar results.. am I missing something?
Ad
Answer
Issue came with the fact the code buffered by =
is escaped by default for security, however to output unescaped return values you can use !=
So a solution to this would be:
each item in posts
p!= item
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad