<%- include("partials/header"); -%>
<h1>Home</h1>
<p><%= startingContent %></p>
<% posts.forEach(function(post){ %>
<h1><%=post.title%></h1>
<p>
<%=post.content.substring(0, 100) + " ..."%>
<!-- This line's giving me an error, I dont know why -->
Read More
</p>
<% }) %> <%- include("partials/footer"); -%>
Normally, it's supposed to reduce the number of characters to be displayed to a specific number(in this case 100).
Related
<ul>
<% if ('contacts'.length) { %> <% 'contacts'.forEach(({ link, name }) => { -%>
<li>
<%= name %>
</li>
<% }) %> <% } %>
</ul>
I have a syntacxis problem with this part of ejs file.What would be the correct syntax?
I try ejslint,but he doesnt support me
I need the following HTML output exactly as shown below:
<section id='option1'>
<a href='#option1'><h6>Option1</h6><span>></span></a>
<div class='content'>Option1 content...</div>
</section>
I am using a Ruby block to create multiple sections like the one shown above in order to build an accordion UI. However, the problem is that the <span> tag won't nest inside the <a> tag properly. I have checked out other SO queries on the subject, but can't seem to find a solution.
What I hope to end up with is a Ruby block that looks something like this:
<% %w[option1 option2].each do |act| %>
<%= tag.section do %>
<%= link_to("#{act}".capitalize, "##{act}", {class: 'centered', data: { turbo_frame:"content"}}) do %>
<%= tag.h6 act do %>
<%= tag.span raw ">" %>
<% end %>
<% end %>
<% end %>
<% end %>
But I get a undefined method 'stringify_keys' for "option1":String
Can someone help me construct a nested content_tag that puts all the required elements in the right place?
Ok, so with some fiddling with the HTML structure, I came up with the following that works:
<div id='accordion'>
<% %w[option1 option2 ... optionN].each do |act| %>
<%= tag.h2(id:"accordion_header", class: "ui-accordion-header") do %>
<%= link_to("#{act}".capitalize, "#{act}") %>
<% end %>
<%= tag.div(id: "#{act}", class: "ui-accordion-content") do %>
<%= render "/sidebars/content/#{controller_name}/#{act}", formats: :html, handlers: :erb %>
<% end %>
<% end %>
</div>
<script>
$("#accordion").accordion();
</script>
I still haven't figured out how to get the anchor tags to respond to the click event and render the appropriate content via turbo-frames yet, so feel free to comment on how to do that. The documentation for Turbo is (at the present) woefully inadequate.
<% var percentage = (data.skills[i].rating / 10) * 100 %>
<div class="progress">
<% var style = `style=width: percentage%` %>
<div class="progress-bar color-1" role="progressbar" aria-valuenow="%= percentage %>"
aria-valuemin="0" aria-valuemax="10" <%= style %>>
<span><%= percentage %>%</span>
</div>
</div>
You need to use <%- for unescaped strings instead of <%= for style to work <%- style %>.
You forgot a < in front of %= here aria-valuenow="%= percentage %>
Also i'm not sure what you think this does style=width: percentage% since percentage% is just a string which will not be replaced by ejs engine.
So the correct code should look like bellow:
<% var percentage = (5 / 10) * 100 %>
<div class="progress">
<% var style = `style="width: ${percentage}px"` %>
<div class="progress-bar color-1" role="progressbar" aria-valuenow="<%= percentage %>"
aria-valuemin="0" aria-valuemax="10" <%- style %>>
<span><%= percentage %>%</span>
</div>
</div>
You can paste the code in this playground to see what the output is.
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.
I am trying to make my site more component based using includes in my application but it just throws an error to the page when I reload it. I have tried:
<%=include _partials/site-head/site-head %>
And I have tried:
<%=include virtual="_partials/site-head/site-head" %>
Here is the code.
<%=include virtual="_partials/site-head/site-head" %>
<h1><%= title %></h1>
<% for(var i=0; i<userlist.length; i++) {%>
<p><%= userlist[i].name %></p>
<% } %>
<%=include virtual="_partials/site-foot/site-foot" %>
Tag <%= is used to output variables, for code need to use <%- %>. So to include views you need to write like this:
<%- include _partials/site-head/site-head.ejs %>
<h1><%= title %></h1>
<% for(var i=0; i<userlist.length; i++) {%>
<p><%= userlist[i].name %></p>
<% } %>
<%- include _partials/site-head/site-foot.ejs %>
Also read this answer.
My Answer that solved this was to check what version of express your using, I was using an old version which didnt like include.