Skip to content

Commit

Permalink
Add documentation for the first block recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Vetter committed Aug 6, 2013
1 parent 4cefd6e commit 37c5b3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Contents:
.. toctree::
:maxdepth: 2

recipes


Indices and tables
Expand Down
38 changes: 38 additions & 0 deletions docs/source/recipes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=======
Recipes
=======

Create a Custom Template Block
------------------------------

Start off by creating a new app in your project, e.g. a ``blocks`` app. Conent
blocks in fancypages are basically Django models that require a few additional
attributes and definitions.

Let's assume we want to create a simple widget that displays a custom template
without providing any additional data that can be edited. All we need to do is
define the following model::

from fancypages.models.blocks import ContentBlock
from fancypages.library import register_content_block

@register_content_block
class MyTemplateBlock(ContentBlock):
name = _("My template")
code = u'my-template'
group = u'My Blocks'
template_name = u'blocks/my_template_block.html'

def __unicode__(self):
return self.name

The first three attributes ``name``, ``code`` and ``group`` are important and
have to be specified on every new content block.

+-----------+---------------------------------------------------------+
| ``name`` | Display name of the content block |
+-----------+---------------------------------------------------------+
| ``code`` | **Unique** code for the block to be identified by |
+-----------+---------------------------------------------------------+
| ``group`` | Blocks can be grouped by using the same group name here |
+-----------+---------------------------------------------------------+

0 comments on commit 37c5b3f

Please sign in to comment.