I'm creating a Go/Hugo Theme with Bootstrap 4 and in my index.html template file I have the code below to iterate through the articles posted:
<div class="col-12 col-md-12" id="main">
<div class="row">
{{- range .Paginator.Pages -}}
{{- if eq .Type "posts"}}
<div class="col-12 col-md-3 col-lg-3">
<figure><img src="{{ .Params.banner }}" /></figure>
<p>{{ .Summary }}</p>
</div>
{{- end -}}
{{- end }}
</div>
</div>
It's not quite ready yet but it already allows me to use a cover image, defined as a FrontMatter parameter, for something more creative than a blog-like style. Here, a sneak-peak.
As you can see there as Pagination implemented as well so I can see whatever is older the the last entries (defined in config.toml and accessed through .Paginator.Pages).
But I was thinking on get rid of this Pagination and transform this listing in a Carousel, but I don't if I would be able to do so with Hugo nor if it's possible to "plug n' play" a Carousel that would working with Bootstrap's existing markup.
How could I accomplish that?
If you can do it in HTML then you can do it with Hugo, so the answer is yes, it's possible. From a brief search on the net there seem to be dozens of carousel implementations for Bootstrap, so just choose one of those.
For example, with the carousel for Bootstrap v4 alpha on the Bootstrap site, you can make a carousel with this code:
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="..." alt="Third slide">
</div>
</div>
</div>
Assuming that you have defined the parameters carouselimage and carouselimagealt in the front matter of all your articles, you could generate this HTML with Hugo by doing this:
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
{{ $paginator := .Paginate (where .Data.Pages "Type" "posts") }}
{{ range $paginator.Pages }}
<div class="carousel-item active">
<img class="d-block img-fluid" src="{{ .Data.carouselimage }}" alt="{{ .Data.carouselimagealt }}">
</div>
{{ end }}
</div>
</div>
Also, I've made your page type here "posts" as you did in your question, but usually in Hugo it is "post", so you might want to check which one you need.
Related
Gallery with carousel
I created a gallery like on the attached picture. I have no problem when I am linking picture from hard drive. I can preview those small pictures in main carousel view by clicking on the them and also using controll buttons on carousel.
The problem I have is how to have the same functionality when loading pictures from the model? The small images after click are displayed randomly on main carousel view.
How to link data-bs-slide-to="" ? Or there is another option?
Below code from liniking from hard drive and using database.
<div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="10000">
<img src="{% static 'bpage/img/f1r.jpg' %}" class="rounded d-block img-fluid mx-auto" alt="...">
</div>
<div class="carousel-item" data-bs-interval="2000">
<img src="{% static 'bpage/img/f2r.jpg' %}" class="rounded d-block img-fluid mx-auto" height="600" alt="...">
</div>
<div class="carousel-item" data-bs-interval="2000">
<img src="{% static 'bpage/img/f3r.jpg' %}" class="rounded d-block img-fluid mx-auto" height="600" alt="...">
</div>
<div class="carousel-item" data-bs-interval="2000">
<img src="{% static 'bpage/img/f4r.jpg' %}" class="rounded d-block img-fluid mx-auto" height="600" alt="...">
</div>
</div>
<!--rest of the carousel-->
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
</div>
<!--- imagaes below carousel-->
<div class="row" >
<div class="col-6 col-md-5 col-lg-4 col-xl-3 ">
<div class="row row-cols-2 row-cols-sm-4">
<div class="col">
<img src="{% static 'bpage/img/f1r.jpg' %}" class="rounded w-100 mt-2" data-bs-target="#carouselExampleInterval" data-bs-slide-to="0">
</div>
<div class="col">
<img src="{% static 'bpage/img/f2r.jpg' %}" class="rounded w-100 mt-2" data-bs-target="#carouselExampleInterval" data-bs-slide-to="1">
</div>
<div class="col">
<img src="{% static 'bpage/img/f3r.jpg' %}" class="rounded w-100 mt-2" data-bs-target="#carouselExampleInterval" data-bs-slide-to="2">
</div>
<div class="col ">
<img src="{% static 'bpage/img/f4r.jpg' %}" class="rounded w-100 mt-2" data-bs-target="#carouselExampleInterval" data-bs-slide-to="3">
</div>
</div>
</div>
</div> ```
Gallery created with models.py
```<div class="container">
<div class="row ">
<div class="col-6 col-md-5 col-lg-4 col-xl-3 ">
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
{% for product in products %}
<div class="carousel-item {% if forloop.first %} active {% endif %}">
<img src="{{ product.image.url }}" class="rounded d-block img-fluid mx-auto" height="600" alt="...">
</div>
{% endfor %}
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
</div>
</div>
<!--- imagaes below carousel-->
<div class="container">
<div class="row" >
<div class="col-6 col-md-5 col-lg-4 col-xl-3 ">
<div class="row row-cols-sm-4 row-cols-2">
{% for product in products %}
<img src="{{ product.image.url }}" class="rounded mt-2" data-bs-target="#carouselExampleControls" data-bs-slide-to="">
{% endfor %}
</div>
</div>
</div> ```
Are you using a for loop to get your images from the model? If you are, then you might be able to map it like this:
data-bs-slide-to="{{ forloop.counter |add:"-1" }}
Which, assuming you are using a for loop to display every image , will backlink your thumbnails to your images.
Problem is that both divs shows on load. I tried to use v-cloak only on one but its not working. If i put on parent div then its not look good while is hidden. Any suggestion how can i display only one div while page is loading, but without v-cloak?
<div class="center_image" v-if="avatarImageSet">
<div class="checked">
<div class="seller_image {{ in_role('BusinessUsers') ? 'agency' : '' }}">
<img src="{{ home_asset('img/very_big_user_icon.png') }}" alt="" />
</div>
<div class="check_profile business">
<i class="fa fa-check"></i>
</div>
</div>
</div>
<div class="center_image" v-else>
<div class="checked">
<div class="seller_image">
<img v-bind:src="user_credentials.avatar" alt="Avatar"/>
</div>
<div class="check_profile business">
<i class="fa fa-check"></i>
</div>
</div>
</div>
This might be happening because of other errors in your code, like:
<img src="{{ home_asset('img/very_big_user_icon.png') }}" alt="" />, you should use v-bind with src
class="seller_image {{ in_role('BusinessUsers') ? 'agency' : '' }}" You should be using dynamic class binding here.
See modified code:
<div class="center_image" v-if="avatarImageSet">
<div class="checked">
<div class="seller_image" :class="{`yourclass`: in_role('BusinessUsers') === 'agency'}">
<img :src="home_asset('img/very_big_user_icon.png')" alt="" />
</div>
<div class="check_profile business">
<i class="fa fa-check"></i>
</div>
</div>
</div>
<div class="center_image" v-else>
<div class="checked">
<div class="seller_image">
<img v-bind:src="user_credentials.avatar" alt="Avatar"/>
</div>
<div class="check_profile business">
<i class="fa fa-check"></i>
</div>
</div>
</div>
I am having a weird issue with responsiveness in my angular app. On one of my pages I have use the md-card and md-list directives inside a div with class col-xs-12:
<div class="col-xs-12 col-sm-12 col-md-12">
<md-card>
<md-card-header>
<md-card-avatar>
<i class="material-icons md-36"></i>
</md-card-avatar>
<md-card-header-text>
<div class="page-title-wrapper pull-left">
<h4 class="page-title">Quizzes</h4>
<div class="page-title-border"></div>
</div>
</md-card-header-text>
</md-card-header>
</md-card>
</div>
<div ng-repeat="quiz in vm.quizzes" class="col-xs-12 col-sm-6 col-md-4">
<md-card>
<md-card-header>
<md-card-avatar>
<i class="material-icons md-36" ng-bind-html="quiz.course.icon_font"></i>
</md-card-avatar>
<md-card-header-text>
<span class="md-title">{{ quiz.course.name }}</span>
<span class="md-subhead">{{ quiz.name }}</span>
</md-card-header-text>
</md-card-header>
<img ng-src="{{ quiz.course.banner_url }}" class="md-card-image" alt="Fundamentals of Networking">
<md-card-content>
<p>
{{ quiz.overview.substr(0, 100) }}{{ (quiz.overview.length > 100 ? '...' : '') }}
</p>
<div class="md-10 pull-left text-meta">
{{ quiz.start_date }} {{ quiz.start_time }}
</div>
<div class="md-10 pull-right text-meta">
{{ quiz.duration }}
</div>
<br>
<hr>
<div class="clearfix"></div>
<md-button class="md-raised md-primary md-12 md-btn pull-right">
<i class="material-icons md-14 pull-left margin-top-10"></i>
<span class="md-text pull-left">
Start Quiz
</span>
</md-button>
</md-card-content>
</md-card>
</div>
Now for some reason when the screen is resized the content is displaced, the container does not resize with the screen so most of the content is hidden by the body. It only displays properly after the page has been reloaded after a screen resize.
So currently as a fix I have put this in my code to refresh or reload the page each time the screen resizes:
/* Reload APP on screen resize */
$(window).bind('resize', function(e)
{
if (window.RT) clearTimeout(window.RT);
window.RT = setTimeout(function()
{
this.location.reload(false); /* false to get page from cache */
}, 100);
});
However I am not satisfied with the screen reloading like this so I would like to know why this is happening and how I can fix it.
The bootstrap carousel is working and looping around images. However, when you first open the web page, the carousel slider displays a empty background for a split-second. Afterwards, it is working properly.
I tried to solve it through this css but does not work.
.carousel-control {
background-color: transparent;
}
There are some questions related to preload whole carousel. What kind of jquery code is needed to do that?
Do you know how to get rid of the split-second empty background?
<div class="carousel slide" id="myCarousel" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="first-slide" src="{% static 'img/img1.jpg' %}" alt="First slide" />
</div>
<div class="item">
<img class="second-slide" src="{% static 'img/img2.jpg' %}" alt="Second slide">
</div>
<div class="item">
<img class="third-slide" src="{% static 'img/img3.jpg' %}" alt="Third slide">
</div>
</div>
<a class="left carousel-control" data-slide="prev" href="#myCarousel"></a>
<a class="right carousel-control" data-slide="next" href="#myCarousel"></a>
</div>
This worked for me.
CSS:
.preload{ display: none; }
HTML
<div class="preload">
<img src="img/img1.jpg" />
<img src="img/img2.jpg" />
<img src="img/img3.jpg" />
</div>
When using BS3 and patterns/designs that are similar to the media object layout:
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="..." alt="...">
</a>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
...
</div>
</div>
Does it make more sense to recreate the pattern using BS3 grids (and thus built-in media queries, sorta like thumbnails)? For example:
<div class="row">
<a class="col-sm-5 col-md-4" href="#">
<img src="holder.js/100%x112" alt="media-like-object">
</a>
<div class="col-sm-6 col-md-7">
<h4 class="hidden-xs">Media heading</h4>
...
</div>
</div>
Or is there some way to utilize the built-in media object responsively? I guess I'm confused as the media object seems to be static. What am I missing?