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

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

64 196

Last Topic: movable type 5 custom fields by kljx on Mar 17, 2010

1004 3223

Last Topic: Create Offline Backup by Jackie on Mar 17, 2010

482 1976

Last Topic: ¿Any command line tool to rebuild MT? by Nicolás on Mar 16, 2010

102 360

Last Topic: Saving an entry...what is happening by jdbeast00 on Mar 12, 2010

57 127

Last Topic: Anyone using Disqus with MT5? by Jim S. on Mar 17, 2010

19 69

Last Topic: Custom main index page by Richard on Feb 7, 2010

43 172

Last Topic: by MG on Feb 20, 2010

11 22

Last Topic: Monthly Calendars Help Needed by joe leblanc on Jan 19, 2010

91 326

Last Topic: SpamLookup Keyword Filter 2.1 not work by b.n09 on Nov 17, 2009

55 205

Last Topic: URL Problems by NoSnaiL on Mar 17, 2010

code.sixapart.com

129 448

Last Topic: Action Stream for Google Buzz by jack lail on Feb 16, 2010

160 498

Last Topic: Installed custom Asset markup by spierce on Mar 15, 2010