I recently added several new Splash Tags for the Splash content management system. If you don’t know about Splash, read my Introduction to Splash article.
- <s: find>
- <s: children-each>
- <s: children-first >
- <s: children-last >
- <s: ifFirst >
- <s: unlessFirst >
- <s: ifLast >
- <s: unlessLast >
There’s a complete list of tags and documentation over on the GitHub Wiki. But, I’ll give you an overview and show you how to use these tags for a blog.
<s:find> This tag looks up a page and stores the page object so that subsequent tags can use that page object.
<s: children-each> The tag finds all the children of a page and loops over them.
<s: children-first > and <s: children-last > finds the first or last child page.
The rest of the tags are all used inside of a <s: children-each> tag. They check to see if the current child page is the first one, last one, or whatever.
Making a Blog page with Splash Tags
Let’s say you have a page named Blog, that has several posts that are child pages of Blog. Then, in the body for the blog page, put something like this:
<cfset thisChild = request.tags.currentChild>
| #DateFormat(thisChild.publishedAt, 'long')#</dt>
<s:find slug=”blog”> finds the blog page, and then <s:children-each> loops over all the pages. By the way, <s:children-each> uses the CFWheels findAll model method, so all of the cool CFWheels parameters are available in <s:children-each>!
If you want to see an example of what this looks like, visit the DonorUp blog page.
All in all, that’s a lot of output for very little programming effort. That’s what I call the secret to programmer happiness!