0sn edited this page Sep 13, 2010 · 2 revisions
Clone this wiki locally

There’s a fancy template tag in /nameremoved/utils/templatetags/flatpage.py. I will tell you about it.

Suppose you have flatpages at urls like:

  • /pants/
  • /pants/chocolate/
  • /pants/jellybeans/
  • /loafers/
  • /loafers/socks/

If you {% load flatpage %} in your flatpage template, there’s a new tag you can use called flatpage_chidren.

If you say {% flatpage_children "/pants/" %} you get new variables, flatpage_root which points to the flatpage object at /pants/, and flatpage_children which points to the flatpage objects at /pants/chocolate/ and /pants/jellybeans/. You get exactly the same result if you say {% flatpage_children "/pants/chocolate/" %} which means you can just use the current page url instead of a static string.

It’s all regular expressions under the hood. Scary! A root flatpage is one that matches ^/[^/]*/$ (so the root page of the site does NOT match even if it is a flatpage). You could probably do some neat stuff by changing that regex.