Permalink
Browse files

Updated template_loaders to allow templates in a mobile folder in a t…

…heme to be loaded before the standard templates.
  • Loading branch information...
1 parent 365621b commit 8382f6684f33390a11a20839574b6f7225462b2a @jmoswalt jmoswalt committed Jul 11, 2012
Showing with 114 additions and 11 deletions.
  1. +16 −11 apps/theme/template_loaders.py
  2. +98 −0 docs/source/templating/mobile.txt
@@ -9,6 +9,7 @@
find_template_loader, make_origin)
from django.utils._os import safe_join
from theme.utils import get_theme_root
+from theme.middleware import get_current_request
non_theme_source_loaders = None
@@ -32,17 +33,21 @@ def get_template_sources(self, template_name, template_dirs=None):
Any paths that don't lie inside one of the
template dirs are excluded from the result set, for security reasons.
"""
- theme_templates = os.path.join(get_theme_root(), 'templates')
- try:
- yield safe_join(theme_templates, template_name)
- except UnicodeDecodeError:
- # The template dir name was a bytestring that wasn't valid UTF-8.
- raise
- except ValueError:
- # The joined path was located outside of this particular
- # template_dir (it might be inside another one, so this isn't
- # fatal).
- pass
+ theme_templates = []
+ if get_current_request().mobile:
+ theme_templates.append(os.path.join(get_theme_root(), 'mobile'))
+ theme_templates.append(os.path.join(get_theme_root(), 'templates'))
+ for template_path in theme_templates:
+ try:
+ yield safe_join(template_path, template_name)
+ except UnicodeDecodeError:
+ # The template dir name was a bytestring that wasn't valid UTF-8.
+ raise
+ except ValueError:
+ # The joined path was located outside of this particular
+ # template_dir (it might be inside another one, so this isn't
+ # fatal).
+ pass
def load_template_source(self, template_name, template_dirs=None):
tried = []
@@ -0,0 +1,98 @@
+.. highlight:: django
+
+Mobile Templates
+================
+
+Tendenci detects mobile browsers and allows you to use that information within your templates. Tendenci will assign a cookie to these visitors. This cookie can be toggled using code below to allow visitors to switch between the mobile and standard versions of a theme.
+
+Mobile Template Folder
+-------------------------
+
+A typical Tendenci theme includes a ``media`` and a ``templates`` folder. You can add a ``mobile`` folder at the root of the theme. If a device is detected to be mobile, Tendenci will first look for the relevant template file in the ``mobile`` folder, then it will move on to the ``templates`` folder, then to the core software. This allows you to build a mobile template and customize other templates specifically for mobile devices.
+
+A very basic theme with mobile and standard layouts could look like this:
+
+- media
+
+ - css
+ - js
+ - img
+
+- mobile
+
+ - default.html
+ - homepage.html
+
+- templates
+
+ - default.html
+ - homepage.html
+ - footer.html
+
+Mobile Toggling
+------------------
+
+When setting up your mobile layout, you can select to show the mobile content using the code below (a mobile stylesheet is included in the example)
+::
+
+ {% if request.mobile %}
+ <link rel="stylesheet" href="{{ THEME_URL }}media/css/styles-mobile.css" type="text/css" />
+ {% endif %}
+
+That same code can be used to include a separate layout, separate navigation, or anything else that you may want to display to mobile viewers but not to desktop browsers. It is **not** necessary to use these ``if`` tags in templates in the ``mobile`` folder.
+
+To take advantage of the cookie opt-out for mobile viewers who want to view the full site, first load the mobile tags at the top of the template:
+::
+
+ {% load mobile_tags %}
+
+To show the link to mobile theme viewers to view full site
+::
+
+ {% if request.mobile %}
+ {% toggle_mobile_link request.get_full_path "View full site" %}
+ {% endif %}
+
+To show the view mobile site link to mobile browser viewers who previously opted out
+::
+
+ {% if request.mobile_browser and not request.mobile %}
+ {% toggle_mobile_link request.get_full_path "View mobile site" %}
+ {% endif %}
+
+The placement of these links, as well as the text of the link is customizable.
+
+Mobile Browsers Supported
+-------------------------
+
+The following mobile browsers are supported:
+
+- iPhone
+- iPod
+- Android
+- Opera Mini
+- Blackberry
+- Droid
+- IEMobile
+- EudoraWeb
+- Fennec
+- Minimo
+- NetFront
+- Polaris
+- HTC_Dream
+- HTC Hero
+- HTC-ST7377
+- Kindle
+- LG-LX550
+- LX265
+- Nokia
+- Palm
+- MOT-V9mm
+- SEC-SGHE900
+- SAMSUNG-SGH-A867
+- SymbianOS
+- DoCoMo
+- ZuneHD
+- ReqwirelessWeb
+- SEJ001
+- SonyEricsson

0 comments on commit 8382f66

Please sign in to comment.