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

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.
<mt:Pages tags="whatever"> <mt:If tag="EntriesCount" ne="0"> Your list output goes here. <mt:Else> Otherwise, this will be shown. </mt:If> </mt:Pages>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 pagesNow 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?
<!-- filtered pages. Show only pages from some folders. --> <mt:setvarblock name="mainpagelist"> <!-- I use this to generate a variable block, and then just call the variable block in the main index template --> <MTPages lastn="5" tag="NOT @sticky" sort_by="authored_on" sort_order="descend"> <MTIfNonEmpty tag="pagefolder"> <!-- will not show pages without a folder--> <!-- set variables --> <mt:setvar name="docsfolder" value="Docs"> <mt:setvar name="webnotesfolder" value="Webnotes"> <mt:setvarblockname="thisfoldername"><mt:folderlabel></mt:setvarblock> <!-- exclude docs and webnotes folders. There must be a more efficient way to do this; I just don't know it--> <mt:unless name="thisfoldername" eq="$docsfolder"> <mt:unless name="thisfoldername" eq="$webnotesfolder"> <!-- this is to 'auto-expire' pages after a given date using a date custom field for each page using the DateTags plugin from staggernation.com--> <mt:ifnonempty tag="PageDataExpiryDate"> <!--pagedataexpirydate is the date custom field--> <!-- if expiry date has not yet passed--> <MTIfDateBeforeOrEqual date="[MTDate format='%m/%d/%y']" target="[MTPageDataExpiryDate format='%m/%d/%y']"> <div> <h2> <a href="<mt:pagepermalink />" title="<mt:pagetitle>"> <$MTPageTitle filters="markdown_with_smartypants" remove_html="1"$> </a> </h2> <div> <!-- what follows is a cocktail of macros. I use Andy Yaco-Mink's better word limit from http://tech.huffingtonpost.com/2006/03/better-word-limit.html to generate a trailing ellipsis (...) after 45 words in the page body. Then I use MTMacros to swap the ... for "more" with "more" linked the page's permalink --> <MTMacroDefine name="paras" string="..."> …[<a href="<$MTPagePermalink$>#more" title="Continue reading "<$MTPageTitle$>""> more </a>]</p> </MTMacroDefine> <$MTPageBody process_tags="1" formatted_words="45" apply_macros="1"$> </div> <div> <mt:pagedate format="%B %e, %Y"> | <mt: folderlabel> </div> </div> </MTIfDateBeforeOrEqual> <mt:else> <!-- if no expiry date is explicitly set: same as above, but it uses DateTags offset functionality to create an expiry date 60 days from the date of the post, and only shows the post or page if it is within that 60 day stretch --> <MTIfDateWithin date="[MTDate format='%m/%d/%y']" start="[MTPageDate format='%m/%d/%y']" end="[MTPageDate format='%m/%d/%y']" end_adjust="60"> <div> <h2> <a href="<mt:pagepermalink />" title="<mt:pagetitle>"> <$MTPageTitle filters="markdown_with_smartypants" remove_html="1"$> </a> </h2> <div> <MTMacroDefine name="paras" string="..."> …[<a href="<$MTPagePermalink$>#more" title="Continue reading "<$MTPageTitle$>""> more </a>]</p> </MTMacroDefine> <$MTPageBody process_tags="1" formatted_words="45" apply_macros="1"$> </div> <div> <mt:pagedate format="%B %e, %Y"> | <mt:folderlabel> </div> </div> </MTIfDateWithin> </mt:else> </mt:ifnonempty> </mt:unless> </mt:unless> </MTIfNonEmpty> </MTPages> </mt:setvarblock> <!-- end --> <!-- print lists --> <mt:if name="mainpagelist" like="/</h2>/"> <!-- This SHOULD check if the 'mainpagelist' varblock has even one entry with a Title <h1> tag. If it does, then proceed; if not, exit. For some reason I couldn't get the Count function to work with Pages, and hence this --> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" width="50%" valign="top"> <!-- Spits out a list title --> <h1>This is my list</h1> <!-- pulls the varblock --> <mt:var name="mainpagelist"> </td> </tr> </table> </mt:if>You could actually use this with the
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.