<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Assign different classes to alternating blog posts? in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200431#M7334</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the 'cycle' tag for that base on HubSpot's Designer &lt;A href="https://designers.hubspot.com/docs/hubl/for-loops#cycle" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To help you get started, use this:&lt;/P&gt;&lt;PRE&gt;{% for content in contents %}
    &amp;lt;div class="post-item {% cycle 'width-one-third','width-two-thirds' %}"&amp;gt;&lt;/PRE&gt;&lt;P&gt;Let me know if it worked like a charm. Happy coding!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;L&lt;/P&gt;</description>
    <pubDate>Thu, 02 Aug 2018 13:34:30 GMT</pubDate>
    <dc:creator>lgerodiaz</dc:creator>
    <dc:date>2018-08-02T13:34:30Z</dc:date>
    <item>
      <title>Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200285#M7324</link>
      <description>&lt;P&gt;Hello there.&lt;/P&gt;&lt;P&gt;I'm trying to figure out how to apply two different css classes&amp;nbsp;to my blog post entries as they are generated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the code below, I have&amp;nbsp;&amp;nbsp;&amp;lt;div class="post-item"&amp;gt; and I would like to append a class to each instance to affect the width of the post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the first one would be:&amp;nbsp;&amp;lt;div class="post-item width-one-third"&amp;gt; and the second would be&amp;nbsp;&amp;lt;div class="post-item two-thirds"&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still feeling my way around the HUBL markup so I'm not sure how to approach this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{% for content in contents %}
                &amp;lt;div class="post-item"&amp;gt;
                    {% if not simple_list_page %}
                    &amp;lt;div class="post-item-inner"&amp;gt;
                       &amp;lt;div class="features-image-block"&amp;gt;                         
                      &amp;lt;a href="{{content.absolute_url}}"&amp;gt;...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 20:24:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200285#M7324</guid>
      <dc:creator>MrCapp</dc:creator>
      <dc:date>2018-08-01T20:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200287#M7325</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20342"&gt;@MrCapp&lt;/a&gt;&amp;nbsp;- You can use the modulus (%)&amp;nbsp; operator for that:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{% for content in contents %}
  &lt;STRONG&gt;{% set extraClass = 'width-one-third' %}
  {% if loop.index % 2 == 0 %}
      {% set extraClass = 'width-two-third' %}
  {% endif %}&lt;/STRONG&gt;
  &amp;lt;div class="post-item &lt;STRONG&gt;{{extraClass}}&lt;/STRONG&gt;"&amp;gt;...&amp;lt;/div&amp;gt;
{% endfor %}&lt;/PRE&gt;&lt;HR /&gt;&lt;P&gt;If this answer helped, please, mark as solved &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;tim@belch.io | &lt;A href="https://forms.belch.io" target="_blank"&gt;forms.belch.io&lt;/A&gt; | Design your own Beautiful HubSpot Forms; No coding necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Drop by and say Hi to me &lt;A href="http://slack.belch.io/" target="_blank"&gt;on slack&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 20:38:47 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200287#M7325</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2018-08-01T20:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200288#M7326</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20342"&gt;@MrCapp&lt;/a&gt;&amp;nbsp;you could use a bit jquery to do this. Something like this could work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$(document).ready(function() {

  $('.blog .post-item:odd').addClass('width-one-third');
  $('.blog .post-item:even').addClass('wdith-two-thirds');

});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 20:37:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200288#M7326</guid>
      <dc:creator>radar</dc:creator>
      <dc:date>2018-08-01T20:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200289#M7327</link>
      <description>&lt;P&gt;Don't mind the emoji haha&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 20:37:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200289#M7327</guid>
      <dc:creator>radar</dc:creator>
      <dc:date>2018-08-01T20:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200431#M7334</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the 'cycle' tag for that base on HubSpot's Designer &lt;A href="https://designers.hubspot.com/docs/hubl/for-loops#cycle" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To help you get started, use this:&lt;/P&gt;&lt;PRE&gt;{% for content in contents %}
    &amp;lt;div class="post-item {% cycle 'width-one-third','width-two-thirds' %}"&amp;gt;&lt;/PRE&gt;&lt;P&gt;Let me know if it worked like a charm. Happy coding!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;L&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 13:34:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200431#M7334</guid>
      <dc:creator>lgerodiaz</dc:creator>
      <dc:date>2018-08-02T13:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200465#M7341</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/67052"&gt;@lgerodiaz&lt;/a&gt;&amp;nbsp;- good find... didn't know about that one.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 15:11:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200465#M7341</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2018-08-02T15:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200516#M7356</link>
      <description>&lt;P&gt;Hey lgerodiaz - thanks for your answer - that worked perfectly. That seems to be a simpler method than tjoyce's answer although that also worked just fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However what I didn't realize was that those classes would be applied the same way for each row of content.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need the classes to reverse for the following row and then keep going back and forth until all the rows of content have been generated. Does that make sense?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The layout on the Hubspot blog shows what I'm trying to get to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="hubbbbb.png" style="width: 910px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/10917i843F105722B9489A/image-size/large?v=v2&amp;amp;px=999" role="button" title="hubbbbb.png" alt="hubbbbb.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how I can do that?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 18:18:14 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200516#M7356</guid>
      <dc:creator>MrCapp</dc:creator>
      <dc:date>2018-08-02T18:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200557#M7370</link>
      <description>&lt;P&gt;It is possible with javascript. I put together a sample for you here. The equation would be (4n - 1) and (4n - 2) in order to get your sequence.&lt;/P&gt;&lt;P&gt;&lt;A href="https://jsfiddle.net/h20nyact/" target="_self"&gt;Here's the fiddle&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;If this answer helped, please, mark as solved &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;tim@belch.io | &lt;A href="https://forms.belch.io" target="_blank"&gt;forms.belch.io&lt;/A&gt; | Design your own Beautiful HubSpot Forms; No coding necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Drop by and say Hi to me &lt;A href="http://slack.belch.io/" target="_blank"&gt;on slack&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 11:30:05 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200557#M7370</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2018-08-03T11:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200564#M7371</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20342"&gt;@MrCapp&lt;/a&gt;&amp;nbsp;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{% for content in contents %}
    &amp;lt;div class="post-item {% cycle &lt;STRONG&gt;'width-one-third','width-two-thirds', 'width-two-thirds','width-one-third'&lt;/STRONG&gt; %}"&amp;gt;&lt;/PRE&gt;&lt;P&gt;Which would generate an HTML like this:&lt;/P&gt;&lt;PRE&gt;&amp;lt;! -- start of cycle --&amp;gt;
&amp;lt;div class="post-item width-one-third"&amp;gt;
&amp;lt;div class="post-item width-two-thirds"&amp;gt;
&amp;lt;div class="post-item width-two-thirds"&amp;gt;
&amp;lt;div class="post-item width-one-third"&amp;gt;
&amp;lt;! -- cycle will repeat again --&amp;gt;
&amp;lt;div class="post-item width-one-third"&amp;gt;
&amp;lt;div class="post-item width-two-thirds"&amp;gt;
&amp;lt;div class="post-item width-two-thirds"&amp;gt;
&amp;lt;div class="post-item width-one-third"&amp;gt;&lt;/PRE&gt;&lt;P&gt;So on and so forth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;L&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 23:00:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200564#M7371</guid>
      <dc:creator>lgerodiaz</dc:creator>
      <dc:date>2018-08-02T23:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200565#M7372</link>
      <description>&lt;P&gt;If you want the items to be grouped inside a row, you can use this code instead&lt;/P&gt;&lt;PRE&gt;{% for content in contents %}
    {{ '&amp;lt;div class="row"&amp;gt;' if loop.index % 2 != 0 }}

        &amp;lt;div class="post-item {% cycle 'width-one-third','width-two-thirds', 'width-two-thirds','width-one-third' %}"&amp;gt;
            ...
        &amp;lt;/div&amp;gt;

    {{ '&amp;lt;/div&amp;gt;' if loop.index % 2 == 0 }}
{% endfor %}&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Aug 2018 23:22:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/200565#M7372</guid>
      <dc:creator>lgerodiaz</dc:creator>
      <dc:date>2018-08-02T23:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/201006#M7432</link>
      <description>&lt;P&gt;Thanks again. That did the trick.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason the most recent post is not appearing&amp;nbsp;as the first post in&amp;nbsp;the list and it's affecting the layout. *sigh*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think once I get that sorted the layout should work as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 13:41:09 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/201006#M7432</guid>
      <dc:creator>MrCapp</dc:creator>
      <dc:date>2018-08-07T13:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Assign different classes to alternating blog posts?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/201008#M7433</link>
      <description>&lt;P&gt;Thanks for the suggestion. I think that would work but I'm trying to avoid JS for this bit.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 13:42:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Assign-different-classes-to-alternating-blog-posts/m-p/201008#M7433</guid>
      <dc:creator>MrCapp</dc:creator>
      <dc:date>2018-08-07T13:42:16Z</dc:date>
    </item>
  </channel>
</rss>

