- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Assign different classes to alternating blog posts?
SOLVEAug 1, 2018 4:24 PM
Hello there.
I'm trying to figure out how to apply two different css classes to my blog post entries as they are generated.
In the code below, I have <div class="post-item"> and I would like to append a class to each instance to affect the width of the post.
So the first one would be: <div class="post-item width-one-third"> and the second would be <div class="post-item two-thirds">.
I'm still feeling my way around the HUBL markup so I'm not sure how to approach this.
Any help is appreciated.
{% for content in contents %} <div class="post-item"> {% if not simple_list_page %} <div class="post-item-inner"> <div class="features-image-block"> <a href="{{content.absolute_url}}">...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Aug 2, 2018 7:00 PM
@MrCapp I think you could further use the 'cycle' tag in this case as it's not limited only up to two values. In fact, we could add multiple. For example:
{% for content in contents %} <div class="post-item {% cycle 'width-one-third','width-two-thirds', 'width-two-thirds','width-one-third' %}">
Which would generate an HTML like this:
<! -- start of cycle --> <div class="post-item width-one-third"> <div class="post-item width-two-thirds"> <div class="post-item width-two-thirds"> <div class="post-item width-one-third"> <! -- cycle will repeat again --> <div class="post-item width-one-third"> <div class="post-item width-two-thirds"> <div class="post-item width-two-thirds"> <div class="post-item width-one-third">
So on and so forth.
L
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content