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

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

695 2910

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 567

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012