Do you want to see a Django Fiber screencast, to get a feel for what it can do for you? Check it out here: http://vimeo.com/ridethepony/django-fiber
Or, if you want to quickly try out Django Fiber on your machine, install the Django Fiber example project: https://github.com/ridethepony/django-fiber-example
Convinced? Want to use Django Fiber in your own Django project? Follow the instructions below:
$ pip install django-fiber
These dependencies are automatically installed:
django-mptt>=0.4.2 django-piston==0.2.3rc1 beautifulsoup>=3.2.0 PIL>=1.1.7 django-staticfiles>=1.0.1 django-compressor>=0.7.1
Optionally, you may need:
textile>=2.1.5 South>=0.7.3
MIDDLEWARE_CLASSES = ( ... 'fiber.middleware.ObfuscateEmailAddressMiddleware', 'fiber.middleware.AdminPageMiddleware', 'fiber.middleware.PageFallbackMiddleware', ... ) TEMPLATE_CONTEXT_PROCESSORS = ( ... 'django.core.context_processors.request', 'staticfiles.context_processors.static_url', 'fiber.context_processors.page_info', ... ) INSTALLED_APPS = ( ... 'mptt', 'staticfiles', 'compressor', 'fiber', ... ) import os BASE_DIR = os.path.abspath(os.path.dirname(__file__)) STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' STATICFILES_FINDERS = ( 'staticfiles.finders.FileSystemFinder', 'staticfiles.finders.AppDirectoriesFinder', 'compressor.finders.CompressorFinder', )
These settings are optional (default values are shown):
FIBER_DEFAULT_TEMPLATE = 'base.html' FIBER_TEMPLATE_CHOICES = [] FIBER_EXCLUDE_URLS = [] FIBER_IMAGES_DIR = 'uploads/images' FIBER_FILES_DIR = 'uploads/files' FIBER_METADATA_PAGE_SCHEMA = {} FIBER_METADATA_CONTENT_SCHEMA = {} COMPRESS = [the opposite of DEBUG]
from django.conf import settings urlpatterns = patterns('', ... (r'^api/v1/', include('fiber.api.urls')), (r'^admin/fiber/', include('fiber.admin_urls')), (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': ('fiber',),}), ... ) if settings.DEBUG: urlpatterns += patterns('staticfiles.views', url(r'^static/(?P<path>.*)$', 'serve'), )
Create database tables:
$ python manage.py syncdb
All static Fiber files need to be symlinked in (or copied to) your media folder:
$ python manage.py collectstatic --link
At the beginning of your template(s), load the Fiber template tags:
{% load fiber_tags %}
Using the Fiber template tags, you can:
- write out content items, that either
- have a specified name
- are linked to a specific location on the current page
- are linked to a specific location on another page
- write out valid XHTML menu structures
- of pages below a named root page (this is the menu name),
- limited to a minimum and maximum level (depth),
- that mark the currently active page,
- optionally expanding all descendants of the currently active page,
- with all possible css hooks you could ever need
You can write out content items with the 'show_content' and 'show_page_content' template tags:
{% show_content "content_item_name" %} {% show_page_content "block_name" %} {% show_page_content other_page "block_name" %}
This shows content item named 'address':
{% show_content "address" %}
This shows content items that are linked to the location named 'content' on the current page:
{% show_page_content "content" %}
This shows content items that are linked to the location named 'content' on another page 'other_page':
{% show_page_content other_page "content" %}
You can write out menus with the 'show_menu' template tag:
{% show_menu "menu_name" min_level max_level ["all_descendants / all"] %}
The menu name refers to a top-level node in the page tree.
The examples below assume the pages are structured like this:
- mainmenu
- Home
- About us
- Mission
- Our people
- Products
- Product A
- Testimonials
- Downloads
- Technical data sheet
- User manual
- Product B
- Downloads
- Product C
- Downloads
- Product A
- Contact
- Newsletter
- Directions
- generalmenu
- Disclaimer
- Privacy statement
Show first and second level pages, below the root page named 'mainmenu':
{% show_menu "mainmenu" 1 2 %}
When the user is currently visiting the 'Home' page, this will show (current pages are bold):
- Home
- About us
- Products
- Contact
When the user is currently visiting the 'Products' page, this will show:
- Home
- About us
- Products
- Product A
- Product B
- Product C
- Contact
As you can see, the sub pages of the currently active 'Products' page are automatically expanded.
When the user is currently visiting the 'Product A' page, this will show:
- Home
- About us
- Products
- Product A
- Product B
- Product C
- Contact
The sub pages of the 'Product A' page are not shown, because they are outside of the specified minimum and maximum levels.
Show pages from level 3 to 5, below the root page named 'mainmenu', and also show all descendants of the currently active page:
{% show_menu "mainmenu" 3 5 "all_descendants" %}
When the user is currently visiting the 'Home' page, this will show an empty menu, since it cannot be determined what level 3 pages are currently active.
However, when the user is currently visiting the 'Product A' page, this will show:
- Product A
- Testimonials
- Downloads
- Technical data sheet
- User manual
- Product B
- Product C
Notice that all pages below the currently active 'Product A' page are expanded because of the 'all_descendants' parameter.
Show all pages, with all pages expanded:
{% show_menu "mainmenu" 1 999 "all" %} {% show_menu "generalmenu" 1 999 "all" %}