README.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. .. _flatpagesfile-chapter:
  2. ======================
  3. flatpagesfile plugin
  4. ======================
  5. This is the flatpages file plugin. It allows you to add pages to your
  6. MediaGoblin instance which are not generated from user content. For
  7. example, this is useful for these pages:
  8. * About this site
  9. * Terms of service
  10. * Privacy policy
  11. * How to get an account here
  12. * ...
  13. How to configure
  14. ================
  15. Add the following to your MediaGoblin .ini file in the ``[plugins]``
  16. section::
  17. [[mediagoblin.plugins.flatpagesfile]]
  18. This tells MediaGoblin to load the flatpagesfile plugin. This is the
  19. subsection that you'll do all flatpagesfile plugin configuration in.
  20. How to add pages
  21. ================
  22. To add a new page to your site, you need to do two things:
  23. 1. add a route to the MediaGoblin .ini file in the flatpagesfile
  24. subsection
  25. 2. write a template that will get served when that route is requested
  26. Routes
  27. ------
  28. First, let's talk about the route.
  29. A route is a key/value in your configuration file.
  30. The key for the route is the route name You can use this with `url()`
  31. in templates to have MediaGoblin automatically build the urls for
  32. you. It's very handy.
  33. It should be "unique" and it should be alphanumeric characters and
  34. hyphens. I wouldn't put spaces in there.
  35. Examples: ``flatpages-about``, ``about-view``, ``contact-view``, ...
  36. The value has two parts separated by commas:
  37. 1. **route path**: This is the url that this route matches.
  38. Examples: ``/about``, ``/contact``, ``/pages/about``, ...
  39. You can do anything with this that you can do with the routepath
  40. parameter of `routes.Route`. For more details, see `the routes
  41. documentation <http://routes.readthedocs.org/en/latest/>`_.
  42. Example: ``/siteadmin/{adminname:\w+}``
  43. .. Note::
  44. If you're doing something fancy, enclose the route in single
  45. quotes.
  46. For example: ``'/siteadmin/{adminname:\w+}'``
  47. 2. **template**: The template to use for this url. The template is in
  48. the flatpagesfile template directory, so you just need to specify
  49. the file name.
  50. Like with other templates, if it's an HTML file, it's good to use
  51. the ``.html`` extensions.
  52. Examples: ``index.html``, ``about.html``, ``contact.html``, ...
  53. Here's an example configuration that adds two flat pages: one for an
  54. "About this site" page and one for a "Terms of service" page::
  55. [[mediagoblin.plugins.flatpagesfile]]
  56. about-view = '/about', about.html
  57. terms-view = '/terms', terms.html
  58. .. Note::
  59. The order in which you define the routes in the config file is the
  60. order in which they're checked for incoming requests.
  61. Templates
  62. ---------
  63. To add pages, you must edit template files on the file system in your
  64. `local_templates` directory.
  65. The directory structure looks kind of like this::
  66. local_templates
  67. |- flatpagesfile
  68. |- flatpage1.html
  69. |- flatpage2.html
  70. |- ...
  71. The ``.html`` file contains the content of your page. It's just a
  72. template like all the other templates you have.
  73. Here's an example that extends the `flatpagesfile/base.html`
  74. template::
  75. {% extends "flatpagesfile/base.html" %}
  76. {% block mediagoblin_content %}
  77. <h1>About this site</h1>
  78. <p>
  79. This site is a MediaGoblin instance set up to host media for
  80. me, my family and my friends.
  81. </p>
  82. {% endblock %}
  83. .. Note::
  84. If you have a bunch of flatpages that kind of look like one
  85. another, take advantage of Jinja2 template extending and create a
  86. base template that the others extend.
  87. Recipes
  88. =======
  89. Url variables
  90. -------------
  91. You can handle urls like ``/about/{name}`` and access the name that's
  92. passed in in the template.
  93. Sample route::
  94. about-page = '/about/{name}', about.html
  95. Sample template::
  96. {% extends "flatpagesfile/base.html" %}
  97. {% block mediagoblin_content %}
  98. <h1>About page for {{ request.matchdict['name'] }}</h1>
  99. {% endblock %}
  100. See the `the routes documentation
  101. <http://routes.readthedocs.org/en/latest/>`_ for syntax details for
  102. the route. Values will end up in the ``request.matchdict`` dict.