We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18809
    • 109 Posts
    Hello,
    I am creating a blog in Modx and I need help. I need help in templating. Its a grid based layout of two colums. I have 2 classes.
    1. <li class="one_half first">
    2. <li class="one_half">
    When I post an article, it will go in "one_half first" class structure, according to template's classes and layout. But when I post second article, it will go in the same class. I want it to change and post it into "one_half" class.
    So I want that, when I post an article, it should go in (1) and then second article in (2) and third in again (1) and like this 1,2,1,2.
    I can;t find any solution myself. I just found that I have to make a tv to choose from 1 and two everytime I post an article. Is there any other, automatic way to do this?

    Note : I am following modx's how to create a blog tutorial and using this :

    [[!getResourcesTag?
    &element=`getResources`
    &elementClass=`modSnippet`
    &tpl=`Proto_BlogPost`
    &hideContainers=`1`
    &pageVarKey=`page`
    &parents=`[[*id]]`
    &includeTVs=`1`
    &includeContent=`1`]]
    [[!+page.nav:notempty=`
    <div class="paging">
    <ul class="pageList">
    [[!+page.nav]]
    </ul>
    </div>
    `]]


    ... and Proto_BlogPost is my blog post chunk where im using those <li> classes.
    Please help.

    This question has been answered by multiple community members. See the first response.

    [ed. note: smashingred last edited this post 12 years, 2 months ago.]
      My Proudly Powerd By Modx site - http://irresistiblemt.in smiley Its simple site but its made in best CMS.
      • 3749
      • 24,544 Posts
      If you use &tplOdd, it will be used for the items with an odd index and &tpl will be used for the even ones.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 18809
        • 109 Posts
        Quote from: BobRay at Jul 16, 2014, 01:05 AM
        If you use &tplOdd, it will be used for the items with an odd index and &tpl will be used for the even ones.

        Thanks alot. As Articles is updated, I am going to use Articles instead of just getresources. So there is option to put "ArticleRowTpl" chunk name to display blog posts. So how can I use the odd and even tpl there? Because I have to put only my chunk name there in "Article Row Chunk".
        I hope you understand what I want to say.

        And one more thing, I am using image tv to select post thumb for each post everytime. I want my post thumb image to automatically fetch from my blog post. Because I am going to import my posts from wordpress, and there are hundreds of posts and there, I have to manually update post thumbs by editing each post. That's why Im looking for better solution to fetch image from blog post and display as post thumb.
        Thanks..
          My Proudly Powerd By Modx site - http://irresistiblemt.in smiley Its simple site but its made in best CMS.
          • 3749
          • 24,544 Posts
          If I'm understanding you, you'll still be using getResources to get the Articles so you will still be able to use &tpl and &tplOdd. Neither getResources nor Articles cares what the name of the chunk used for either one is. Any chunk will work as long as it contains placeholders that are set in the process.




            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 18809
            • 109 Posts
            Quote from: BobRay at Jul 16, 2014, 02:10 PM
            If I'm understanding you, you'll still be using getResources to get the Articles so you will still be able to use &tpl and &tplOdd. Neither getResources nor Articles cares what the name of the chunk used for either one is. Any chunk will work as long as it contains placeholders that are set in the process.
            Actually Im not using getresources directly now. Now im using Articles as its fixed for 2.3
            Articles has an option to input your chunk name for ArticleRowTpl(blog post tpl) and there you have to enter only chunk name, so how can I use that to use tpl and tplOdd ?

            One more thing, I tried -
            &tpl=`Proto_BlogPost` and &tplOdd=`Proto_BlogPost2` in getresources as you suggested, its not working.

            So here in my case, nothing is working to get 1,2,1,2 thing (portfolio blog post)
            Im attaching images, please have a look. ITa a bootstrap template.
              My Proudly Powerd By Modx site - http://irresistiblemt.in smiley Its simple site but its made in best CMS.
              • 3749
              • 24,544 Posts
              I don't think you can do it with just Articles without hacking the Articles code or creating a custom snippet to do the display.

              I can't think of any reason why your getResources method isn't working unless it's the cache.

              Are there TVs in your two chunks? If not a custom snippet should be fairly simple.

              Can you post the two Tpl chunks?


                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 18809
                • 109 Posts
                Sure,... its so simple code but I don;t know why its not working.

                <li class="one_half first">
                          <article class="clear">
                            <figure class="post-image"><img src="[[+tv.PostThumb:pthumb=`w=570&h=140&q=60&zc=1&aoe=1`]]"  alt="[[+pagetitle]] pictures" title="[[+pagetitle]]" ></figure>
                            <header>
                              <h2 class="blog-post-title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>
                              <div class="blog-post-meta">
                                <ul>
                                  <li class="blog-post-date">
                                    <time><strong>Completed:</strong> [[+publishedon:strtotime:date=`%b %d, %Y`]]</time>
                                  </li>
                                  <li class="blog-post-cats">[[+tv.tags:notempty=`[[!tolinks? &items=`[[+tv.tags]]` &tagKey=`tag` &target=`1`]]`]]</li>
                                </ul>
                              </div>
                            </header>
                            <p>[[+introtext:default=`[[+content:ellipsis=`300`]]`]]</p>
                            <footer class="read-more"><a href="[[~[[+id]]]]">Read More »</a></footer>
                          </article>
                        </li>


                .....and in 2nd tpl, just
                <li class="one_half first">
                changed to
                <li class="one_half">

                :/
                  My Proudly Powerd By Modx site - http://irresistiblemt.in smiley Its simple site but its made in best CMS.
                  • 3749
                  • 24,544 Posts
                  I thought maybe I could throw together a quick custom snippet for you, but the Tpl chunks are much too complex for a quick solution.

                  I would not call the Tpl chunks simple at all. Consider that with the tv.tags tag, you have a placeholder tag, inside a snippet tag, inside an output modifier, inside a placeholder, inside a chunk that's being processed by a snippet that's inside a resource field. With the level of nesting, I'm surprised that it works at all.

                  Does it work correctly if you just use the &tpl chunk?
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 18809
                    • 109 Posts
                    Simply using &tpl is working just fine. But not two tpls. sad
                      My Proudly Powerd By Modx site - http://irresistiblemt.in smiley Its simple site but its made in best CMS.
                    • discuss.answer
                      • 3749
                      • 24,544 Posts
                      I don't know what to say. huh I don't see anything you're doing wrong, but this is working perfectly for me:

                      tplOdd chunk:

                      <br />ODD: [[+pagetitle]]


                      tplEven chunk:

                      <br />Even: [[+pagetitle]]



                      [[!getResources? 
                          &tplOdd=`tplOdd` 
                          &tpl=`tplEven` 
                          &parents=`38` 
                          &showUnpublished=`1` 
                          &showHidden=`1`
                      ]]


                      I don't have getResourcesTag installed, but the properties should all be passed directly through to getResources in your case.

                      The only thing I can suggest is to make sure the two chunks are spelled exactly as they are in the snippet tag. You might also try taking out the underscores, making the chunk names more different and turning off hideContainers to see if it makes any difference.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting