Index: django/contrib/flatpages/templatetags/__init__.py
===================================================================
Index: django/contrib/flatpages/templatetags/flatpages.py
===================================================================
--- django/contrib/flatpages/templatetags/flatpages.py	(revision 0)
+++ django/contrib/flatpages/templatetags/flatpages.py	(revision 0)
@@ -0,0 +1,55 @@
+
+from django import template
+from django.contrib.flatpages.models import FlatPage
+from django.utils.translation import ugettext as _
+from django.conf import settings
+
+register = template.Library()
+
+class FlatpageNode(template.Node):
+    def __init__(self, context_name, starts_with=None):
+        self.context_name, self.starts_with = context_name, starts_with
+        if self.starts_with:
+            self.starts_with = template.Variable(starts_with)
+        self.flatpages = FlatPage.objects.filter(sites__id=settings.SITE_ID)
+        
+    def render(self, context):
+        if self.starts_with:
+            self.flatpages = self.flatpages.filter(\
+                url__startswith=self.starts_with.resolve(context))
+        context[self.context_name] = self.flatpages
+        return ''
+
+
+def get_flatpages(parser, token):
+    """
+    Template tag that returns flatpages availible on the site.    
+    An optional argument, 'starts_with', can be applied only return pages 
+    whose urls start with that base url. This can be a variable or a string, 
+    it resolves from context. 
+    
+    Syntax is {% get_flatpages ['url_starts_with'] as context_name %}
+    example: 
+    {% get_flatpages '/about/' as about_pages %}
+    {% for page in about_pages %}...{% endfor %}
+    """
+    bits = token.split_contents()
+    if len(bits) is 3:
+        if bits[1] != 'as':
+            raise template.TemplateSyntaxError, _("%s expects a syntax of %s "
+                "['url_starts_with'] as context_name" % (bits[0], bits[0]))
+        return FlatpageNode(bits[2])
+    elif len(bits) is 4:
+        if bits[2] != 'as':
+            raise template.TemplateSyntaxError, _("%s expects a syntax of %s "
+                "['url_starts_with'] as context_name" % (bits[0], bits[0]))
+        return FlatpageNode(bits[3], bits[1])
+    else:
+        raise template.TemplateSyntaxError, _("%s expects a syntax of %s "
+            "['url_starts_with'] as context_name" % (bits[0], bits[0]))
+
+
+register.tag('get_flatpages', get_flatpages)
+
+
+
Index: tests/regressiontests/flatpages/views.py
===================================================================
--- tests/regressiontests/flatpages/views.py	(revision 0)
+++ tests/regressiontests/flatpages/views.py	(revision 0)
@@ -0,0 +1 @@
+# Create your views here.
Index: tests/regressiontests/flatpages/__init__.py
===================================================================
Index: tests/regressiontests/flatpages/tests.py
===================================================================
--- tests/regressiontests/flatpages/tests.py	(revision 0)
+++ tests/regressiontests/flatpages/tests.py	(revision 0)
@@ -0,0 +1,82 @@
+from django.test import TestCase
+from django.contrib.flatpages.models import FlatPage
+from django.contrib.sites.models import Site
+
+current_site = Site.objects.get_current()
+
+
+class FlatpageTest(TestCase):
+    """Test for contrib.flatpages"""
+    # Site.objects.clear_cache()
+
+    
+    def setUp(self):
+        
+        page = FlatPage(
+            url='/page1/', 
+            title='Some page', 
+            content="<p>Some text that shouldn't be automatcially escaped</p>",
+            registration_required=False,
+            )
+        page.save()
+        page.sites.add(current_site)
+        page.save()
+        
+        registrationPage = FlatPage(
+            url='/registered/', 
+            title='register for this page', 
+            content="great you are registered",
+            registration_required=True,
+            )
+        registrationPage.save()
+        registrationPage.sites.add(current_site)
+        registrationPage.save()
+        
+        fallbackPage = FlatPage(
+            url='/accounts/login/', 
+            title='This page should not be seen', 
+            content=" ",
+            registration_required=True,
+            )
+        fallbackPage.save()
+        fallbackPage.sites.add(current_site)
+        fallbackPage.save()
+        
+    def testPage(self):
+        page = self.client.get('/page1/')
+        self.failUnlessEqual(page.status_code, 200)
+        self.assertContains(page, "<p>Some text that shouldn't be automatcially escaped</p>")
+        
+    def testRegistration(self):
+        registrationPage = self.client.get('/registered/')
+        self.assertRedirects(registrationPage, '/accounts/login/?next=/registered/', target_status_code=302)
+        
+    def testFallback(self):
+        fallbackPage = self.client.get('/accounts/login/')
+        self.assertNotContains(fallbackPage, 'This page should not be seen', status_code=302)
+        
+    def testTag(self):
+        from django import template
+        # because of the way flatpages are loaded in the tests this is the 
+        # equivilent of {% load flatpages %}
+        template.add_to_builtins('django.contrib.flatpages.templatetags.flatpages')
+        t = template.Template("""{% get_flatpages as flatpages %}
+{% for page in flatpages %}
+{{ page.title }}
+{% endfor %}
+
+{% get_flatpages '/registered/' as registered_pages %}
+{% for page in registered_pages %}
+{{ page.title }}
+{% endfor %}
+
+{% get_flatpages some_var as registered_pages %}
+{% for page in registered_pages %}
+{{ page.title }}
+{% endfor %}""")
+        r = t.render(template.Context({'some_var':'/accounts/'}))
+        self.assertEquals(r, 
+            """\n\nThis page should not be seen\n\nSome page\n\nregister""" +\
+            """ for this page\n\n\n\n\nregister for this page\n\n\n\n\n""" +\
+            """This page should not be seen\n""")
+
+
Index: tests/regressiontests/flatpages/models.py
===================================================================
--- tests/regressiontests/flatpages/models.py	(revision 0)
+++ tests/regressiontests/flatpages/models.py	(revision 0)
@@ -0,0 +1 @@
+# Create your models here.
Index: tests/regressiontests/flatpages/templates/flatpages/default.html
===================================================================
--- tests/regressiontests/flatpages/templates/flatpages/default.html	(revision 0)
+++ tests/regressiontests/flatpages/templates/flatpages/default.html	(revision 0)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
+    "http://www.w3.org/TR/REC-html40/loose.dtd">
+<html>
+<head>
+<title>{{ flatpage.title }}</title>
+</head>
+<body>
+{{ flatpage.content }}
+</body>
+</html>
Index: docs/flatpages.txt
===================================================================
--- docs/flatpages.txt	(revision 7698)
+++ docs/flatpages.txt	(working copy)
@@ -134,3 +134,38 @@
 
 .. _automatic HTML escaping: ../templates/#automatic-html-escaping
 
+
+Getting a list of Flatpages in your Templates
+=============================================
+
+**New in Django development version**
+
+The Flatpages contrib app also comes with a template tag. From your templates
+you can access this tag via {% load flatpages %} and you get access to a 
+get_flatpages tag that returns flatpages availible on the site.    
+An optional argument, 'starts_with', can be applied only return pages 
+whose urls start with that base url. This can be a variable or a string, 
+it resolves from context. 
+
+Syntax is {% get_flatpages ['url_starts_with'] as context_name %}
+example:
+ 
+    {% get_flatpages '/about/' as about_pages %}
+    <ul>
+        {% for page in about_pages %}
+            <li><a href="{{ page.url }}">{{ page.title }}</a></li>
+        {% endfor %}
+    </ul>
+
+
+If you wish to filter flatpages out by registration required, you can place an
+if statment around your for loop:
+
+    {% get_flatpages '/contact/' as contact_pages %}
+    {% for page in contact_pages %}
+        {% if not user.is_authenticated and page.registration_required %}
+            <h3><a href="{{page.url}}">{{page.title}}</a></h3>
+        {% endif %}
+    {% endfor %}
+
+
