All SilvaLayout-based templates for Bethel's web pages share some elements. Some design elements include the left navigation menu, common template settings, and even the placement of headers and other elements within the rendered page. To achieve this, there is a base skin which all Bethel templates will extend.
This skin is the IBethelBase skin, and is located in the BethelTemplates product, in the templates directory. It is currently intended that all Bethel templates be placed in separate directories within 'templates'.
The current structure is as follows:
adxmenu
- a resourceDirectory serving the shared navigation menu files
basemacros.pt
- Contains the standard "page" macro, which all public views will use
bethelbase.py
- Contains additional view code business logic (BaseViewMixin)
- Content and Container classes which extend BaseViewMixin and Products.SilvaLayout.browser.silvaview.[Content|Container]
- IBaseBethelSkin
- BaseMacros class
configure.zcml
- component registration for the adxMenu resourceDirectory, the bethel_macros browser:view (.bethebase.BaseMacros), and the IBaseBethelSkin interface.
bu
postees
- The postees html email skin / application
Naming Conventions
There appears to be some odd view / resourceDirectory name lookup behaviour (in fact it appears to be opposite of what one one expect). To assist in getting around this, view names and resource directories (in particular) which have a general enough purpose should prepend the template name in front of the "general" view name, e.g. "buassets" rather than simply "assets"
adxMenu resourceDirectory
See basemacros.pt for information on how the adxMenu resources in this directory are used. adxMenu is used for the left navigation popups. Enabling and controlling the left navigation menu uses template properties which are shared (the same names and values) across all IBethelBase skins.the template
basemacros.pt
This page template contains the "page" macro, which will be used by all public views. This macro contains the general "any bethel site will use these this" components, like adxMenu, google analytics, the standard page title and including prototype js and the jscalendar. The following slots are defined:
- meta — in <head>, for various meta tags
- title — in <head>, to override the standard html page title
- headers — in <head>, a general slot for template-specific items
- script — in <head>, for "in-page" javascript
- remote_scripts — in <head>, to reference remote javascripts
- extra-css — in <head>, for any sort of extra css (via <style> or <link>)
- body — in <body>, where the template body goes
Note also basemacros contains a check for a request variable, head_stuffer. This should be created as a list. Any items in this list are placed at the bottom of the <head>, so that external sources can embed custom css styles in a standards-compliant way. This head_stuffer could also be used by silva content types which have custom css included with them (e.g. SilvaUCLGallery).
basemacros can easily be used by the Bethel layouts. The bethelbase.BaseMacros class is registered as a browser:view on all ISilvaObjects. So, within the layout's template, all you need to do is reference that view's "page" attribute:
<metal:block use-macro="context/@@bethel_macros/page">
bethelbase.py
This python module contains an additional view code mixin class, new base Container and Content classes which inherit this mixin, the IBethelBase skin, and the BaseMacros class.
BaseViewMixin
This class has helper functions and business logic for the page templates.
- get_site_config
finds the nearest BethelSite configuration object. BethelSites have the id 'site_config' and contain the template preferences for the site.
- call_site_config_script
BethelSites have a "scripts" folder. Certain template preferences can point to a script in this folder which will be rendered (and usually the output will be placed in the template somewhere). This method will call the script and return the output. It takes into account the fact that the script may not exist, and returns None in the case.
- is_script_or_menu
Some preferences provide a choice of a menu or a script located in the site configs menus or scripts folders. Menu ids start with 'm@', which scripts don't. This method checks the value, and returns true if the value exists as a menu in the menus folder, or is a script in the scripts folder.
- suppress_title_if_set
Currently this suppresses ALL document titles. In the future, this may take into account 'suppress_title' properties set in the hierarchy of the model, or look at a custom Silva metadata set.
should_suppress_template
There are some circumstances where the template should (almost entirely) be suppressed. An example is the content of a popup window (which provides a FAQ answer or something). This method performs the following tests to see if the template should be hidden:
- setting a "suppress_template" property in a propertysheet
- putting hide_template=1 in the request
- XXX todo: hide_template setting in metadata
- should_display_blink_backlink
Some public areas display a link back to BLink if the client just came from BLink
(e.g. the www.bethel.edu/bethel-news/ site)
- get_title
Checks if the current view is preview or public, and returns either the contents published title, or the unpublished title (or id, if the title is blank).
NOTE: this method should be used in the templates to get the document title!
Likely, this should be in the SilvaView class.
- compute_base_href
Compute the <base> tag's href zope does this incorrectly, because SilvaDocuments are object managers, so it's <base> tag ends up like: http://site.com/container/document/ it should be: http://site.com/container/document
- set_content_type
Is used to set the HTTP Response's content type and encoding.
- compute_school_color
For the BU template, each school (cas/caps/gs/seminary) has a different style/color for the content's title and submenu.
- compute_analytics_codes
Determine the analytics codes for each domain which uses google analytics. NOTE: if new domains are added, their analytics codes need to be added to this method. This method contains a dictionary mapping the third-level domain name to a 2-tuple of (analytics code, domain). The "domain" is used for www.bethel.edu, which shares the same analytics code with the bethelnet.
- get_school_link_logo_name
For the BU template, based on the "school" preference, return the homepage url, the graphic (in ++resource++buassets), and the school's name.
- get_virtual_host_root
Return the virtual host root (container) of the current content. This is used (and should be used) as the root for any resourceDirectory assets (like the school logos, adxMenu, etc)
- getWelcome
This method computes the salutation which appears in the Personal Bar. This computes it for the BU template (and portal api), the bethelnet template looks slightly different.
- renderSidebarMenu, renderHorizontalBarMenu, renderContentMenu
These methods take the site_config and the menu name as parameters, and render the menu as a sidebar menu (which uses adxMenu), a top menu (in the Personal Bar), or a sub menu (below the content's page title). These all call adapters to do the actual work.
- get_parcel_from_metadata
A parcel is a silva object that is to be placed above or below the page content, within the div#bu-content-pad. This method takes parcel metadata location (either header or footer), looks it up in the bethel-layout metadata set (content_header|footer), resolves the object and returns it, or None if not found.
__call__
This method is called when the view is rendered. It does a few things:
- Checks the "bethel-layout:secure_transport" metadata field. If this is true, but the page is being served over vanilla http, a redirect to https is issued and rendering is stopped.
- The site_config is looked up, the request is setup, and the title and template are suppressed (if applicable).
- The view's page template is called (this happens to be self.index())
Content, Container
These are both redefined view classes which inherit from BaseViewMixin and the appropriate SilvaView view Content or Container view class.
IBaseBethelSkin
This class defines the skin.
BaseMacros
This class is a view on ISilvaObject (in the IBaseBethel layer) which looks up macros defined globally for that layer. Current the only macro defined is the "page" macro for the public views.
configure.zcml
This is the component registration xml file. It registers the adxMenu resourceDirectory, registers the bethel_macros browser view, and the IBaseBethelSkin as a layout.
BU
The BU template is used for all (most) of the public web sites hosted from Silva.
postees
This is a skin which enables the design of html emails (a.k.a. postees) and efficient email delivery of these postees.
- how basemacros is tied in to the layouts
- bethelbase.content, container include a mixing class, BaseViewMixin, as well as extending the silvaview classes of the same name
- BaseViewMixin contains helper methods to assist in the rendering of the templates
- refer to baseviewmixin code for most complete documentation