Testing if a list is empty in textpattern
Posted: June 14, 2012 Filed under: Applications, Technical Notes, Textpattern | Tags: Computers, conditional statements 1 Comment »Let’s say you have a section on a webpage like the “current courses” section in the right menu bar my teaching webspace.
This draws its list from articles in the section “teaching” that have “current_interest” as a category.
The problem comes between semesters while I am preparing my syllabi. If no course has a category “current_interest” you end up with a header and no content.
What you need is something that checks whether there is content to display and then presents different material based on the outcome of that check. You might delete the section entirely, or, as I have done, display a placeholder message.
Textpattern has a tag for this. But since I’d never used it before, I thought I’d link to an example of how to use it here. Here’s the code I use, based on the example in the blog cited in the last link:
- Current courses:<txp:variable name=”hasarticles” value=” />
- I’m not teaching any courses at the moment. I will post syllabi for future courses as they become available.
[…] you write your posts with so much whimsy that is very nice reading them. –Dulcelina, commenting on “Testing if a list is empty in textpattern.” […]