problem while accessing to partial views in express - node.js

here's my views file: views/profile.ejs
<body>
<% include partial/nav.ejs %>
<!-- <%- include('partial/nav.ejs'); %> -->
<h1> Welcome to <%= person %> profile</h1>
<p>
<strong>The age: </strong><%= proObj.age%>
</p>
<p>
<strong>Relationship Status: </strong><%= proObj.relation_status%>
</p>
<div>
<p>
<strong>Hobbies: </strong>
<% hobbies.forEach(function(item){ %>
<li> <%= item %> </li>
<% }); %>
</p>
</div>
</body>
and this partial views file: views/partial/nav.ejs
<nav>
<ul>
<li>Home</li>
<li>Contact</li>
when i reload the website i got this error popped into the server
SyntaxError: Unexpected identifier in C:\Users\Fo0ola\Desktop\SERVER-SIDE\views\profile.ejs while compiling ejs

Related

Issue while using ejs syntax

This is my ejs file(_post.ejs):
<link rel="stylesheet" href="/css/home.css">
<div id="home-container">
<% if(locals.user){%>
<section id="feed-posts">
<h4>Posts</h4>
<form action="/posts/create" method="post" id="new-post-form">
<textarea name="content" cols="30" rows="3" placeholder="Type here..." required></textarea>
<input type="submit" value="Post">
</form>
</section>
<%}%>
<section id="posts-wall" >
<ul>
<% for(post of Posts){ %>
<%- include('_post') -%>
<hr>
<% } %>
</ul>
</section>
<section id="user-friends">
<h4>Friends</h4>
<% for(u of all_users){%>
<p>
<%= u.username %>
</p>
<%}%>
</section>
</div>
<script src="/js/home_posts.js"></script>
Error :
Error: /Users/nishantbhatia/Desktop/nodews/codial/views/home.ejs:17
15| <ul>
16| <% for(post of Posts){ %>
>> 17| <%- include('_post') -%>
18| <hr>
19| <% } %>
20| </ul>
I have included the closing tags as well. Really not sure abt the error. Any help would be appreciated.I tried to read the documentation still no clue.
The syntax should be ,remove - from closing tag. See the docs
<section id="posts-wall" >
<ul>
<% for(post of Posts){ %>
<%- include('_post') %>
<hr>
<% } %>
</ul>
</section>

getting error in EJS file while running res.render

getting this error:
missing ) after argument list in C:\Users\yoniy\Desktop\YelpCamp\views\campgrounds\index.ejs while compiling ejs
and it's the index.ejs file :
<!-- <%- include "../partials/header" %> -->
<header class="jumbotron">
<div class="container">
<h1><span class="glyphicon glyphicon-tent"></span> Welcome To YelpCamp!</h1>
<p>View campgrounds from all over the world</p>
<p>
<a class="btn btn-primary btn-lg" href="/campgrounds/new">Add New Campground</a>
</p>
<p>
<form action="/campgrounds" method="GET" class="form-inline" id="campground-search">
<div class="form-group">
<input type="text" name="search" placeholder="Campground search..." class="form-control">
</div>
</form>
</p>
</div>
</header>
<div class="row text-center flex-wrap" id="campground-grid">
<%- campgrounds.forEach(function(campground){ %>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<img src="<%= campground.image %>">
<div class="caption">
<h4><%= campground.name %></h4>
</div>
<p>
More Info
</p>
</div>
</div>
<%- }); %>
</div>
<!-- <%- include "../partials/footer" %> -->
can't find the syntax error that I get.
thanks for help !
You need to use flow control tags <% for non output parts of your template. In this case the following lines need to be changed:
<%- campgrounds.forEach(function(campground){ %>
Should instead be:
<% campgrounds.forEach(function(campground){ %>
And this line:
<%- }); %>
Should be:
<% }); %>
Update for additional Error
Your formatting for including additional files is incorrect:
<!-- <%- include "../partials/header" %> -->
Should be:
<%- include("../partials/header.ejs") %>
Same for the footer:
<!-- <%- include "../partials/footer" %> -->
Should be:
<%- include("../partials/footer.ejs") %>
Though I cannot validate your paths are correct as I do not know your directory structure.

SilverStripe (3.6.2) Search returning assets folder contents

I haven't enabled Search on SilverStripe before, but it seems pretty easy. I've followed steps from 2 other projects (although they are 3.5 version projects but not sure that makes a difference or not) that have search enabled as well as the tutorial offered on SilverStripe's site, and for some reason, I'm getting asset folder items (i.e. images) in my search results. It only seems to happen if I click to search and nothing has been entered into the search field.
There should be no asset items returned at any time for search, and if there is no search query, then there should be a message saying nothing was entered or something. I noticed that using the default $SearchForm setup provided by the basic install gives me the desired results, but not for the form I'm using (which does work on 2 other SilverStripe sites--I checked and confirmed).
I'm not sure what I'm missing? I feel like everything is done correctly, and I would like to use the setup I have now to give me more styling ability:
From _config.php:
FulltextSearchable::enable();
From my Header.ss file:
<!-- SEARCH BAR -->
<form class="navbar-form navbar-left nav-right-left search-form" id="SearchForm_SearchForm" action="/home/SearchForm" method="get" enctype="application/x-www-form-urlencoded">
<fieldset style="font-size: 0;">
<div class="field text nolabel search-holder">
<input name="Search" placeholder="Search" class="form-control search-field text nolabel active search-box" />
</div>
<div class="ja-search-box">
<button class="icon search-button smiths-search-btn" type="submit"><i class="glyphicon glyphicon-search pull-right"></i></button>
</div>
</fieldset>
</form>
The Search Results page:
<div class="main" role="main">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div id="Content" class="searchResults">
<h1 class="brand-red">$Title</h1>
<% if $Query %>
<p class="searchQuery">You searched for "{$Query}"</p>
<% end_if %>
<% if $Results %>
<ul id="SearchResults">
<% loop $Results %>
<li>
<h4>
<a href="$Link">
<% if $MenuTitle %>
$MenuTitle
<% else %>
$Title
<% end_if %>
</a>
</h4>
<% if $Content %>
<p>$Content.LimitWordCountXML</p>
<% end_if %>
<a class="readMoreLink" href="$Link" title="Read more about "{$Title}"">Read more about "{$Title}"...</a>
</li>
<% end_loop %>
</ul>
<% else %>
<p>Sorry, your search query did not return any results.</p>
<% end_if %>
<% if $Results.MoreThanOnePage %>
<div id="PageNumbers">
<div class="pagination">
<% if $Results.NotFirstPage %>
<a class="prev" href="$Results.PrevLink" title="View the previous page">←</a>
<% end_if %>
<span>
<% loop $Results.Pages %>
<% if $CurrentBool %>
$PageNum
<% else %>
$PageNum
<% end_if %>
<% end_loop %>
</span>
<% if $Results.NotLastPage %>
<a class="next" href="$Results.NextLink" title="View the next page">→</a>
<% end_if %>
</div>
<p>Page $Results.CurrentPage of $Results.TotalPages</p>
</div>
<% end_if %>
</div>
</div>
</div>
</div>
</div>
By default, the full text search will search array('SiteTree', 'File')
http://api.silverstripe.org/en/3.1/class-FulltextSearchable.html
I would try changing your FulltextSearchable::enable(); line to FulltextSearchable::enable(array('SiteTree'));
I haven't tried this before and am not sure if it will work.

How to create a pagination system in Hexo

I love using Hexo.. :)
I've setup custom page. Is it possible to show all post in my page as paginated?
Using site.posts got me all post without pagination.
What should I do to get all post as paginated from page?
Thanks.
In the main configuration file _config.yml, there is a per_page variable to allow you to choose how many post you want ot display per page.
Create a template, index.ejs for example :
<% page.posts.each(function(post) { %>
<article>
// do what you have to do to display each post
</article>
<% }) %>
<%- partial('pagination', {type: 'page'}) %>
As you can see, We use the page variable to get 7 posts.
After that, create an other template pagination.ejs, that allow you to navigate through the page :
<div class="pagination-bar">
<ul class="pagination">
<% if (page.prev) { %>
<li class="pagination-prev">
<% if (page.prev === 1) { %>
<a class="btn btn--default btn--small" href="<%- url_for(' ') %>">
<% } else { %>
<a class="btn btn--default btn--small" href="<%- url_for(page.prev_link) %>">
<% } %>
<i class="fa fa-angle-left text-base icon-mr"></i>
<span><%= __('pagination.newer_posts') %></span>
</a>
</li>
<% } %>
<% if (page.next) { %>
<li class="pagination-next">
<a class="btn btn--default btn--small" href="<%- url_for(page.next_link) %>">
<span><%= __('pagination.older_posts') %></span>
<i class="fa fa-angle-right text-base icon-ml"></i>
</a>
</li>
<% } %>
<li class="pagination-number"><%= _p('pagination.page', page.current) + ' ' + _p('pagination.of', page.total) %></li>
</ul>
</div>
I wrote a Hexo theme : Tranquilpeak, I recommend you to check the source code to understand how I built it and of course read the official Hexo documentation

showing MongoDB document value to EJS in a loop

I'm working on a node project. And node is very new to me so sorry if I ask a lot of stupid questions.
I'm trying to show all of my topics on my index.ejs. The root file already shows them in the console log but I can't seem to get them to show in the view.
The view already loops and knows that there are 2 topics, but the content is empty.
This is my code from the routes/index.js
router.get('/', function(req, res, next) {
Topic.find({}).exec(function(err, topic)
{
if(err){
console.log('There ware no topics');
return next(err)
}
else
{
console.log('Whoop whoop there are some topics');
res.render('index', { topic: topic } );
console.log("Logging data: " + topic);
console.log("Loggin data title out db: " + topic.topicTitle);
console.log("Loggin data desc out db: " + topic.topicDescription);
console.log("Loggin data date out db: " + topic.topicDateCreated);
}
});
});
module.exports = router;
And here is how I try to show it in my views/index.ejs
<ul>
<% for(var i = 0; i < topic.length; i++) {%>
<li>
<div class="post animated fadeInLeft">
<div class="wrap-ut pull-left">
<div class="userinfo pull-left">
<div class="avatar">
<img src="images/avatar.jpg" alt="default avatar" />
<p class="moderator"> <%= topic.fbUsername %> </p>
</div>
</div>
<div class="posttext pull-left">
<h2 class="topictitle"><a href="/topicdetail/{topic_id}" <%= topic.topicTitle %> </a></h2>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</li>
<% } %>
</ul>
The topic variable is an array, so you need to pass the index in order to get the proper Topic document. For instance:
<%= topic[i].fbUsername %>
Your view should look like:
<ul>
<% for(var i = 0; i < topic.length; i++) {%>
<li>
<div class="post animated fadeInLeft">
<div class="wrap-ut pull-left">
<div class="userinfo pull-left">
<div class="avatar">
<img src="images/avatar.jpg" alt="default avatar" />
<p class="moderator"> <%= topic[i].fbUsername %> </p>
</div>
</div>
<div class="posttext pull-left">
<h2 class="topictitle"> <%= topic[i].topicTitle %> </h2>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</li>
<% } %>
</ul>
UPDATE
You also forgot to close the tag here:
--------------------------------------------------------↴
<h2 class="topictitle"><a href="/topicdetail/{topic_id}" <%= topic[i].topicTitle %> </a></h2>
Closing the tag, I was able to see the titles:
<h2 class="topictitle"> <%= topic[i].topicTitle %> </h2>

Resources