We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Hi there:

    I’ve followed and implemented Shaun McCormick’s incredible blog tutorial on multiple sites and it works great. Now trying to take it to the next level by adding a thumbnail image on the right-hand side of each blog summary on the blog articles listing page. I want it so that the site editor can upload an image by way of a TV.

    Cutting to the chase, the solution I’ve implemented works great in any other page besides the blog summary page.

    Here are the steps I’ve followed:

    1. I created the blog (well, a news page in my case) by following the instructions on this page: http://rtfm.modx.com/display/revolution20/Creating+a+Blog+in+MODx+Revolution which works great.
    2. To implement the image, I created a TV with the name of newsSummaryThumbnail, giving it an input type of image. Input Option Values are .jpg, .png. Output Type is default. Template Access is set to BlogPostTemplate (see blog tutorial above...I used the same names as on that tutorial).
    3. Installed the If snippet. Thanks to ’pleth’ for his help on this page: http://modxcms.com/forums/index.php/topic,62869.0.html for how to implement it.
    4. Did some CSS work to create a DIV to contain and place the thumbnail, floated to the right.
    5. In the blogPost chunk (again, see blog tutorial above) I placed the following code at the top:

    [[!If? &subject=`[[*newsSummaryThumbnail]]` &operator=`empty` &then=`` &else=`<div id="news_summary_thumbnail"><img src="[[*newsSummaryThumbnail]]" /></div>`]]


    The ’news_summary_thumbnail’ is the CSS ID that places the code on the page.

    The whole code on the blogPost page looks like:

    [[!If? &subject=`[[*newsSummaryThumbnail]]` &operator=`empty` &then=`` &else=`<div id="news_summary_thumbnail"><img src="[[*newsSummaryThumbnail]]" /></div>`]]
    <div class="post">
    <h2 class="title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>
    <p class="post-info">Posted by [[+createdby:userinfo=`fullname`]]</p>
    <div class="entry">
    <p>[[+introtext]]</p>
    </div>
    <p class="postmeta">
    <span class="links">
     <span class="date">[[+publishedon:strtotime:date=`%b %d, %Y`]] | <a href="[[~[[+id]]]]" class="readmore">Read more</a></a>
    </span>
    </span>
    </p>
    </div>


    6. Tested the thing by uploading an image by way of my created TV.

    ...nothing showed.

    Some observations:

    1. When I put something between the empty backticks, such as the word ’test’, like:

    [[!If? &subject=`[[*newsSummaryThumbnail]]` &operator=`empty` &then=`test` &else=`<div id="news_summary_thumbnail"><img src="[[*newsSummaryThumbnail]]" /></div>`]]


    ...and have nothing else in the TV, then the word ’test’ shows up okay, telling me that the system works in general (as in, the thing is empty, so show the word ’test’). It’s just that the ’then show this, else’ part thinks there is nothing to show even if I do have something in the TV.

    2. When I test the code by placing it in other pages, it works great, including the placement of the DIV.
    3. When I change the TV so that the Input Type is something else, such as Textarea (mini)...to rule out an image-specific problem...it still doesn’t work.

    Can anyone spot what might be wrong? Are there any other suggestions to accomplish what I’m trying to accomplish?

    Thank you in advance.

    Revo 2.0.6
    PHP Version 5.2.10
      • 31902
      • 342 Posts
      Still trying to get this thing to work. One other thing I’ve tried is to temporarily change the code to:

      [[!If? &subject=`1` &operator=`empty` &then=`` &else=`2`]]


      In other words, the statement now says "if the subject is 1, which it is hard-coded as such, then show 2". This worked, meaning, that the system showed a "2" instead of the "1" or "empty", which tells me that the code itself is working. This leaves me to believe that there is something off about the formatting/syntax of the code around the TVs. Something about the presentation of the TVs within the code.

      Any ideas?
        • 31902
        • 342 Posts
        I love talking to myself grin

        I just noticed something that might just have changed the nature of this thread question. It seems that this blog code cannot display the contents of TVs in general, whether it is within the If snippet code I mentioned above or just by itself. And, I’m talking anywhere within this bunch of code:

        <h2 class="title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>
        <p class="post-info">Posted by [[+createdby:userinfo=`fullname`]]</p>
        <div class="entry">
        <p>[[+introtext]]</p>
        </div>
        <p class="postmeta">
        <span class="links">
         <span class="date">[[+publishedon:strtotime:date=`%b %d, %Y`]] | <a href="[[~[[+id]]]]" class="readmore">Read more</a></a>
        </span>
        </span>
        </p>
        </div>
        


        As a test, if I try to utilize the If snippet code I was asking about using the introtext placeholder, like this:

        [[!If? &subject=`[[+introtext]]` &operator=`empty` &then=`` &else=`[[+introtext]]`]]
        


        ...it tests fine. If I hard-code text within it, as already explained, it tests fine. Just TVs (any input type)

        Can anyone explain why?
          • 31902
          • 342 Posts
          Okay, hopefully this gives something back to the community... I got it to work. This is how:

          Instead of this:

          [[!If? &subject=`[[*yourTVname]]` &operator=`empty` &then=`` &else=`<div id="css_id_here"><img src="[[*yourTVname]]" /></div>`]]


          ...use this:

          [[!If? &subject=`[[+tv.yourTVname]]` &operator=`empty` &then=`` &else=`<div id="css_id_here"><img src="[[+tv.yourTVname]]" /></div>`]]


          At this point, adjust CSS, stir and enjoy.
            • 35527
            • 11 Posts
            I actually did things a touch differently after working from your model. I used this code in my chunk instead:
            <div id="thumbnail"><img src="[[+tv.newsThumb]]" alt="[[+pagetitle]]"/></div>


            I also set a default value for newsThumb so that if the user didn’t pick an image a default one was used instead. Don’t know if that would be of use to you, but it was for what I’m doing.
              - moltis