Comments: on this page. Click to read or post your own.

Class SSViewer

Description

The SSViewer executes a .ss template file.

The SSViewer class handles rendering of .ss templates. In addition to a full template in the views folder, a template in views/Content or views/Layout will be rendered into $Content and $Layout, respectively.

Compiled templates are cached. If you put ?flush=1 on your URL, it will force the template to be recompiled. This is a hack; the system should really detect when a page needs re-fetching.

Works with the global $_TEMPLATE_MANIFEST which is compiled by ManifestBuilder->getTemplateManifest(). This associative array lists all template filepaths by "identifier", meaning the name of the template without its path or extension.

Example:

  1.  array(
  2.   'LeftAndMain' =>
  3.   array (
  4.      'main' => '/my/system/path/cms/templates/LeftAndMain.ss',
  5.   ),
  6.  'CMSMain_left' =>
  7.    array (
  8.      'Includes' => '/my/system/path/cms/templates/Includes/CMSMain_left.ss',
  9.    ),
  10.  'Page' =>
  11.    array (
  12.      'themes' =>
  13.      array (
  14.        'blackcandy' =>
  15.        array (
  16.          'Layout' => '/my/system/path/themes/blackcandy/templates/Layout/Page.ss',
  17.          'main' => '/my/system/path/themes/blackcandy/templates/Page.ss',
  18.        ),
  19.        'blue' =>
  20.        array (
  21.          'Layout' => '/my/system/path/themes/mysite/templates/Layout/Page.ss',
  22.          'main' => '/my/system/path/themes/mysite/templates/Page.ss',
  23.        ),
  24.      ),
  25.    ),
  26.    // ...
  27.  )

  • todo: Fix the broken caching.

Located in /sapphire/core/SSViewer.php (line 50)

Object
   |
   --SSViewer
Direct descendents
Class Description
SSViewer_FromString Special SSViewer that will process a template passed as a string, rather than a filename.
Variable Summary
static string $current_theme
static mixed $options
static mixed $topLevel
Method Summary
static string current_theme ()
static void flush_template_cache ()
static void fromString ( $content)
static string getTemplateContent (string $identifier)
static string getTemplateFile (string $identifier)
static string getTemplateFileByType (string $identifier, string $type)
static void hasTemplate ( $templateList)
static void parseTemplateContent ( $content, [ $template = ""])
static void setOption ( $optionName,  $optionVal)
static void set_theme (string $theme)
static void topLevel ()
SSViewer __construct (string|array $templateList)
void exists ()
void process ( $item)
void setTemplateFile (string $type, string $file)
void templates ()
Variables
static string $current_theme = null (line 66)
  • access: protected
static mixed $options = array(
'rewriteHashlinks' => true,
)
(line 176)
  • access: protected
static mixed $topLevel = array() (line 180)
  • access: protected
boolean $rewriteHashlinks = true (line 61)
  • access: protected

Inherited Variables

Inherited from Object

Object::$builtInMethods
Object::$class
Object::$classConstructed
Object::$extensions
Object::$extension_instances
Object::$extraMethods
Object::$extraStatics
Object::$statics
Object::$static_cached
Methods
static method current_theme (line 85)
static string current_theme ()
static method flush_template_cache (line 262)

Clears all parsed template files in the cache folder.

Can only be called once per request (there may be multiple SSViewer instances).

static void flush_template_cache ()
static method fromString (line 71)

Create a template from a string instead of a .ss file

static void fromString ( $content)
  • $content
static method getTemplateContent (line 248)

Used by <% include Identifier %> statements to get the full unparsed content of a template file.

static string getTemplateContent (string $identifier)
  • string $identifier: A template name without '.ss' extension or path.
static method getTemplateFile (line 212)

Searches for a template name in the current theme:

  • themes/mytheme/templates
  • themes/mytheme/templates/Includes
Falls back to unthemed template files.

Caution: Doesn't search in any /Layout folders.

static string getTemplateFile (string $identifier)
  • string $identifier: A template name without '.ss' extension or path.
static method getTemplateFileByType (line 229)
  • return: Full system path to a template file
  • access: public
static string getTemplateFileByType (string $identifier, string $type)
  • string $identifier: A template name without '.ss' extension or path
  • string $type: The template type, either "main", "Includes" or "Layout"
static method hasTemplate (line 155)

Returns true if at least one of the listed templates exists

static void hasTemplate ( $templateList)
  • $templateList
static method parseTemplateContent (line 345)
static void parseTemplateContent ( $content, [ $template = ""])
  • $content
  • $template
static method setOption (line 173)

Set a global rendering option.

The following options are available:

  • rewriteHashlinks: If true (the default), <a href="#..."> will be rewritten to contain the current URL. This lets it play nicely with our <base> tag.

  • access: public
static void setOption ( $optionName,  $optionVal)
  • $optionName
  • $optionVal
static method set_theme (line 78)
static void set_theme (string $theme)
  • string $theme
static method topLevel (line 181)
  • access: public
static void topLevel ()
Constructor __construct (line 95)

Pass the SilverStripe template to be used.

  • access: public
SSViewer __construct (string|array $templateList)
  • string|array $templateList: If passed as a string with .ss extension, used as the "main" template

Redefinition of:
Object::__construct()

Redefined in descendants as:
dontRewriteHashlinks (line 191)

Call this to disable rewriting of <a href="#xxx"> links. This is useful in Ajax applications.

It returns the SSViewer objects, so that you can call new SSViewer("X")->dontRewriteHashlinks()->process();

  • access: public
void dontRewriteHashlinks ()
exists (line 197)
  • access: public
void exists ()

Redefinition of:
Object::exists()
Returns true if this object "exists", i.e., has a sensible value.
process (line 275)

The process() method handles the "meat" of the template processing.

  • access: public
void process ( $item)
  • $item

Redefined in descendants as:
setTemplateFile (line 485)
  • access: public
void setTemplateFile (string $type, string $file)
  • string $type: "Layout" or "main"
  • string $file: Full system path to the template file
templates (line 477)

Returns the filenames of the template that will be rendered. It is a map that may contain

'Content' & 'Layout', and will have to contain 'main'

  • access: public
void templates ()

Inherited Methods

Inherited From Object

Object::__construct()
Object::addMethodsFrom()
Object::addStaticVars()
Object::addWrapperMethod()
Object::add_extension()
Object::allMethodNames()
Object::buildMethodList()
Object::cacheToFile()
Object::cacheToFileWithArgs()
Object::create()
Object::createMethod()
Object::defineMethods()
Object::exists()
Object::extend()
Object::extInstance()
Object::getCustomClass()
Object::hasExtension()
Object::hasMethod()
Object::invokeWithExtensions()
Object::is_a()
Object::loadCache()
Object::parentClass()
Object::sanitiseCachename()
Object::saveCache()
Object::set_stat()
Object::set_uninherited()
Object::stat()
Object::strong_create()
Object::uninherited()
Object::useCustomClass()
Object::__call()
Object::__toString()
blog comments powered by Disqus

Documentation generated on Sun, 19 Oct 2008 06:46:25 +1300 by phpDocumentor 1.3.2