default userpic

How to test if a container tag has any values to return?

Vote 0 Votes

Say I want to show a block that contains a list of Pages, but I only want to show it if there are any pages (that meet my filter criteria, like author= , include_blog=, tags=)

How would I test for this? If I can at all... :)

Reported on Movable Type 4.2

4 Replies

| Add a Reply
  • I can't test this right now, so you can be the guinea pig and let us know. It should work conceptually, but I don't know off-hand how picky the EntriesCount tag is going to be about its context.



    Your list output goes here.

    Otherwise, this will be shown.

    You can, of course, just drop the Else.

    We're hopefully taking advantage of the fact that as far as the data is concerned, pages are mostly just a special variety of entries(They're even in the same db table.) On the off chance this doesn't work, like if EntriesCount demands to be inside an Entries block(there's no PagesCount equivalent), you might try re-doing the Pages container as Entries with the class_type attribute set to "page" to force it to look at pages instead.

  • Thanks Su.
    Your first guess works. :)

    It doesn't quite solve my problem though because if mt:pages is empty, it won't spit out what's inside of it anyways (my "list"). What I want to hide is the title of the list, if there is no list to show...

    eg:

    List of pages






    Now I guess I'd have to put all that html that's outside the Pages container, inside of it and then, if there is a list to print, keep it from being iterated and repeated...

    sorta like this:




    List of pages








    anyways. in my current case, i only wan tto show the one most recent anyways so it's ok, but what if...


    Now I need to go find out why multi-blog include_blog= doesn't work in Dynamic templates... and how to fix that.

  • um... totally forgot about mt:PagesHeader and mt:PagesFooter

    case closed. thnx to Su.

  • I have actually used this, _without_ the PagesHeader/Footer tags. Perhaps some of it does what you want?





    sort_order="descend">











    target="[MTPageDataExpiryDate format='%m/%d/%y']">


    " title="">






    …[
    #more"
    title="Continue reading """>
    more
    ]



    apply_macros="1"$>


     | 





    start="[MTPageDate format='%m/%d/%y']"
    end="[MTPageDate format='%m/%d/%y']" end_adjust="60">


    " title="">
    remove_html="1"$>




    …[
    #more"
    title="Continue reading """>
    more
    ]

    apply_macros="1"$>


     | 












    /">





    This is my list





    You could actually use this with the

    unique="1"
    attribute for entries and pages to generate a second list and then have the lists appear in two columns on a single page.

    Not claiming this is great code or even terribly efficient, but it seems to do the job.

    By the way, if you do copy-paste this code, you may have to remove some line-breaks I had to add in here.

Add a Reply

Forum Groups

513 1681

Last Topic: Google Analytics by Argentina Elections on May 27, 2009

202 880

Last Topic: Welcome to Movable Type by solle on May 27, 2009

49 204

Last Topic: Odd problem with searches - need help by Phill M on May 24, 2009

11 42

Last Topic: Community Solution -- but where? by webmoney on Mar 16, 2009

25 99

Last Topic: Search enhancement? by Rob on Apr 14, 2009

10 21

Last Topic: Comment Box Missing by rushskeith on Jan 9, 2009

90 318

Last Topic: Getting to the settings on Post Office by Rob G on Apr 2, 2009

code.sixapart.com

104 373

Last Topic: Login/Registration issue by Gaurav Sharma on May 26, 2009

90 307

Last Topic: HTML Printer-Friendly page shrinks by Mikki on May 19, 2009