I have a sidebar item which contains a list of comments. I want this item to show only if there are any available comment in the beginning and in order for my template to work I have to put a different style to the first comment than the rest. All the comments are being passed on my Model.
Here is my approach:
#if(Model.Comments?.Count > 0) {
<div class="sidebar_item">
<div class="item_inner slider">
<h4>See what students say:</h4>
<div id="single_banner">
<ul class="slides">
#for (int i = 0; i < Model.Comments.Count; i++)
{
if (i > 0){
<li style="display:none;">
}
#if( i == 0)
{
<li>
}
#Model.Comments[i].Comment
<div class="carousal_bottom">
<div class="thumb">
<img src="img/courses/testi_thumb.png" draggable="false" alt="" />
</div>
<div class="thumb_title">
<span class="author_name">#Model.Comments[i].Student</span>
</div>
</div>
</li>
}
</ul>
</div><!--end banner-->
</div><!--slider-->
</div><!--end sidebar item-->
}
The problem is that this doesn't work and I get errors that some curly brackets are missing or that some elements haven't closed properly. Any help appreciated.
I get errors that [...] some elements haven't closed properly.
The following code isn't recommended because the engine isn't smart enough to determine start/ends for html elements in c# code:
if (i > 0){
<li style="display:none;">
}
#if( i == 0)
{
<li>
}
So I generally put the logic directly in the tag:
<li style="#(i > 0 ? "display:none;" : string.Empty)">
However I'm not really a fan of logic in my view. Additionally to make things easier IMHO, I would have a comment display template. And I personally think there is no good reason to not use classes. Eventually my code would look like:
controller:
foreach(var comment in Model.Comments)
{
comment.IsVisible = comment == Model.Comments.First();
}
view:
// Update Model with Property
// bool HasComments { get { return Comments.Any(); } }
// Then the code actually reads/documents itself
#if(Model.HasComments) {
<div class="sidebar_item">
<div class="item_inner slider">
<h4>See what students say:</h4>
<div id="single_banner">
<ul class="slides">
#Html.DisplayFor(m => m.Comments);
</ul>
</div><!--end banner-->
</div><!--slider-->
</div><!--end sidebar item-->
}
displaytemplates/comments.cshtml
#{
// View logic, it only deals with html/css/javascript
var liClass = model.IsVisible ? string.Empty : "is-not-visible";
}
<li class="#liClass">
#Model.Comments[i].Comment
<div class="carousal_bottom">
<div class="thumb">
<img src="img/courses/testi_thumb.png" draggable="false" alt="" />
</div>
<div class="thumb_title">
<span class="author_name">#Model.Student</span>
</div>
</div>
</li>
Less code and more encapsulated.
I'd also recommend reading Philip Walton - Decoupling Your HTML, CSS, and JavaScript
Related
How to remove tabs in NopCommerce 4.40.3. I would like to remove these two Tabs below in NopCommerce. There is no CSS where I can display: none;
Product tags
Products specifications
Im using NopCommerce NoSource Code and Noble Theme
Thanks in advance
To modify in theme, you don't need to have the source code. Open Themes > NobleTheme > Views > Product > ProductTemplate.Grouped.cshtml (also in ProductTemplate.Simple.cshtml). Replace the code from line# 105 to 134 by this given code.
<div class="product-details-tabs">
<ul class="nav nav-tabs">
#if (!string.IsNullOrEmpty(Model.FullDescription))
{
<li class="active">#T("products.compare.fulldescription")</li>
}
#*#if (!string.IsNullOrEmpty(#Html.PartialAsync("_ProductTags", Model.ProductTags).ToString()))
{
<li>#T("Products.Tags")</li>
}
#if (!string.IsNullOrEmpty(#Html.PartialAsync("_ProductSpecifications", Model).ToString()))
{
<li>#T("Products.Specs")</li>
}*#
</ul>
<div class="tab-content">
#if (!string.IsNullOrEmpty(Model.FullDescription))
{
<div class="full-description tab-pane fade in active" id="description">
#Html.Raw(Model.FullDescription)
</div>
}
#*<div class="product-tags tab-pane fade" id="tags">
#await Html.PartialAsync("_ProductTags", Model.ProductTags)
</div>
<div class="product-specification fade tab-pane" id="specification">
#await Html.PartialAsync("_ProductSpecifications", Model.ProductSpecificationModel)
</div>*#
</div>
</div>
This will not render HTML code for product tag and specification tabs.
I expect li inside ul to be divided into 3 parallel lists of elements next to each other. However, the list appears in a straight list.
I expected col-xs-3 to do the job but it does not seem to work. Suggestions to fix this?
return <div id="col_sub_1">
<ul className="col-xs-3 sub-menu-width ">
{
childitem.map(function(subcat,subcatindex){
{/*--LEAF WHEN NO CHILD ELEMENTS */}
return <li>
{
subcat.id !=54 ? <a className="event_menu_item_desktop"><span> {subcat.name}</span></a> : null
</li>
})
}
</ul>
</div>
You need to add col-xs-3 to <li> tag but not to <ul> element. Also You are not properly closed expression.
Keep in mind always that you need to add unique key to the top element inside loop in react. Try this
return <div id="col_sub_1">
<ul className="sub-menu-width ">
{
childitem.map((subcat,subcatindex) => (
<li key={subcat.id} className="col-xs-3">
{subcat.id !=54 ? <a className="event_menu_item_desktop"><span> {subcat.name}</span></a> : null}
</li>
))}
</ul>
</div>
I am creating an audio player of sorts and i have run into a brick wall. I have added a progress bar that updates according to the song being played.
However, I want the progress bar to be clickable and to jump to the time of the track when its clicked (like every regular player).
<div class="music-stream-wrapper">
<ul class="music-stream">
<li>
<div class="player-wrapper">
<div class="album-art">
<img src="https://i1.sndcdn.com/artworks-000108593302-0ek7n6-t120x120.jpg" alt="" />
</div>
<div class="meta-controls">
<div class="play-controls">
<!-- Content -->
<div class="track">
<h4 class="title">Tail toddle - Unknown</h4>
<span class="author">john.doe</span>
<span class="uploaded">a few seconds ago</span>
</div>
<div class="spectrum">
<div class="play-pause-button">
</div>
<div class="spectrum-wrapper">
<div id="spectrum_11"></div>
<div class="progress">
<progress value="0" max="1"></progress>
</div>
</div>
</div>
</div>
<div class="intent">
<ul class="buttons">
<li>Like</li>
<li>Download</li>
<li>Share</li>
</ul>
<ul class="meta">
<li><span class="liked">♥ 13</span></li>
<li><span class="played">► 123</span></li>
<li><span>♥ 3</span></li>
</ul>
</div>
</div>
</div>
</li>
</ul>
</div>
<audio src="http://tonycuffe.com/mp3/tailtoddle_lo.mp3" id="mockSong"></audio>
I have created a mock player in CodePen heres the url: View in CodePen
I ended up using a jQuery UI slider and updating it dynamically as the track position changed.
It will help you. try to evaluate what you desire for
http://jsfiddle.net/ryanhagz/8u76B/20/
HTML
<div id="progress"></div>
<div id="back">back</div>
<div id="cont">cont</div>
JAVASCRIPT
//PROGRESS BAR
$("#progress").progressbar({
value: 0
});
//UPDATING PROGRESS BAR WHEN CONTINUE BUTTON CLICKED
var currValue = 0,
toValue = 0;
$("#cont").button().click(function () {
currValue = $("#progress").progressbar("value");
if (currValue + 25 <= 100) {
toValue = currValue + 25;
animateProgress();
}
});
//DECREASING PROGRESS BAR WHEN GO BACK BUTTON CLICKED
$("#back").button().click(function () {
currValue = $("#progress").progressbar("value");
if (currValue - 25 >= 0) {
toValue = currValue - 25;
animateProgress();
}
});
function animateProgress() {
if (currValue < toValue) {
$("#progress").progressbar("value", currValue + 1);
currValue = $("#progress").progressbar("value");
setTimeout(animateProgress, 4);
} else if (currValue > toValue) {
$("#progress").progressbar("value", currValue - 1);
currValue = $("#progress").progressbar("value");
setTimeout(animateProgress, 4);
}
}
I have random white space inside my website.
My HTML (Laravel) is build like this:
<ul class="thumbnails" style="max-width: 100%;">
#foreach($img as $image)
<li class="span2 thumbnail">
<div class="overflow-hidden">
<img src="{{ Config::get('app.url') }}/{{ $image }}" />
</div>
</li>
#endforeach
</ul>
This is the output:
And every time I refresh the page, there is another white space.
How can I fix this?
You might want to read up on the grid system to understand why this is happening.
Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on .rows.
In other words, if you look at bootstrap.css:
.row {
margin-right: -15px;
margin-left: -15px;
}
You can fix your code adding the row class to your <ul> element so you have:
<ul class="thumbnails row">
Or, just add the margin-left and margin-right properties.
am i correct that you want the thumbnails to line up 5 times, than start a new row of 5?
Then you have to build in a counter that closes a row, and start a new row:
Beware of code: i do not know laravel, went true documentation to write this, it could be wrong, main focus here is the idea i am giving you:
<ul class="thumbnails" style="max-width: 100%;">
<?php $i=0 ?>
#foreach($img as $image)
<li class="span2 thumbnail">
<div class="overflow-hidden">
<img src="{{ Config::get('app.url') }}/{{ $image }}" />
</div>
</li>
<?php $i++ ?>
#if ($i === 5)
</ul><ul class="thumbnails" style="max-width: 100%;">
#endif
#endforeach
</ul>
And be sure to read the answer by WEX, about the grid system.
I would like to create a image and text menu in Sliverstripe as shown here:
I was thinking to have jquery select an individual ID and replace the background image. How ever Silverstripe gives me the menu as you see below. How can I go about setting up this menu?
Output
<ul>
<li class="current">
<a title="video" href="/cfl/index.php/">Home</a>
</li>
<li class="link">
<a title="alarm" href="/cfl/index.php/about-us/">About Us</a>
</li>
<li class="link">
<a title="auto" href="/cfl/index.php/contact-us/">Contact Us</a>
</li>
</ul>
Template File
<nav class="primary">
<span class="nav-open-button">²</span>
<ul>
<% loop $Menu(1) %>
<li class="$LinkingMode">$MenuTitle.XML</li>
<% end_loop %>
</ul>
</nav>
Thanks.
this should be pretty easy, in SilverStripe templates you can do anything you can do in normal HTML. With additional variables and features of course.
so, you can simply give the items a ID or a css class.
let me show you an example:
<nav class="primary">
<span class="nav-open-button">²</span>
<ul>
<% loop $Menu(1) %>
<li class="$LinkingMode position-$Pos" id="$URLSegment">$MenuTitle.XML</li>
<% end_loop %>
</ul>
</nav>
you see, I added position-$Pos which will become position-1, position-2, and so on.
also, I added an ID, in this case, it will be the URLSegment of that page.
so now you can use CSS or javascript to get that item, eg here some CSS to set a background:
.position-1 { background: green; }
.position-2 { background: yellow; }
.position-3 { background: blue; }
// we can also use the ID to style the element:
#home {
display: block;
width: 100px;
height: 100px;
background-image: url(http://placehold.it/100x100);
}
in in any javascript code you can of course do the same (in your case the framework jquery):
jQuery(document).ready(function($) {
$('.position-1').hover(function() {
alert('you moved over the first item');
});
});
however, I strongly urge you to use CSS, there is no reason for using javascript to do a simple task like setting a background image.