SilverStripe 2.4 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
Version: master
  • master
  • 3.1
  • 3.0
  • 2.4
  • tagfield

Packages

  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • publishers
    • reports
    • security
    • tasks
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • installer
  • None
  • PHP
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets

Classes

  • ArrayData
  • Requirements
  • Requirements_Backend
  • SSViewer
  • SSViewer_Cached_PartialParser
  • SSViewer_FromString
  • SSViewer_PartialParser
  • ViewableData
  • ViewableData_Customised
  • ViewableData_Debugger

Class SSViewer

Parses a template file with an *.ss file extension.

In addition to a full template in the templates/ folder, a template in templates/Content or templates/Layout will be rendered into $Content and $Layout, respectively.

A single template can be parsed by multiple nested SSViewer instances through $Layout/$Content placeholders, as well as <% include MyTemplateFile %> template commands.

Themes

See http://doc.silverstripe.org/themes and http://doc.silverstripe.org/themes:developing

Caching

Compiled templates are cached via SS_Cache, usually on the filesystem. If you put ?flush=all on your URL, it will force the template to be recompiled.

Manifest File and Structure

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:

array(
 'LeftAndMain' =>
 array (
        'main' => '/my/system/path/cms/templates/LeftAndMain.ss',
 ),
'CMSMain_left' =>
  array (
    'Includes' => '/my/system/path/cms/templates/Includes/CMSMain_left.ss',
  ),
'Page' =>
  array (
    'themes' =>
    array (
      'blackcandy' =>
      array (
        'Layout' => '/my/system/path/themes/blackcandy/templates/Layout/Page.ss',
        'main' => '/my/system/path/themes/blackcandy/templates/Page.ss',
      ),
      'blue' =>
      array (
        'Layout' => '/my/system/path/themes/mysite/templates/Layout/Page.ss',
        'main' => '/my/system/path/themes/mysite/templates/Page.ss',
      ),
    ),
  ),
  // ...
)

Direct known subclasses

SSViewer_FromString

Package: sapphire\view
See: http://doc.silverstripe.org/themes
See: http://doc.silverstripe.org/themes:developing
Located at sapphire/core/SSViewer.php

Methods summary

public static
# set_source_file_comments( boolean $val )

Set whether HTML comments indicating the source .SS file used to render this page should be included in the output. This is enabled by default

Set whether HTML comments indicating the source .SS file used to render this page should be included in the output. This is enabled by default

Parameters

$val
boolean
$val
public static boolean
# get_source_file_comments( )

Returns

boolean
public static SSViewer
# fromString( mixed $content )

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

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

Returns

SSViewer
public static
# set_theme( string $theme )

Parameters

$theme
string
$theme The "base theme" name (without underscores).
public static string
# current_theme( )

Returns

string
public static string
# current_custom_theme( )

Returns

string
public
# __construct( string|array $templateList )

Parameters

$templateList
string|array
$templateList If passed as a string with .ss extension, used as the "main" template. If passed as an array, it can be used for template inheritance (first found template "wins"). Usually the array values are PHP class names, which directly correlate to template names. <code> array('MySpecificPage', 'MyPage', 'Page') </code>
public static
# hasTemplate( mixed $templateList )

Returns true if at least one of the listed templates exists

Returns true if at least one of the listed templates exists

public static
# setOption( mixed $optionName, mixed $optionVal )

Set a global rendering option. The following options are available:
- rewriteHashlinks: If true (the default), will be rewritten to contain the
current URL. This lets it play nicely with our <base> tag.
- If rewriteHashlinks = 'php' then, a piece of PHP script will be inserted before the hash
links: "<?php echo $_SERVER['REQUEST_URI']; ?>". This is useful if you're generating a
page that will be saved to a .php file and may be accessed from different URLs.

Set a global rendering option. The following options are available: - rewriteHashlinks: If true (the default), will be rewritten to contain the current URL. This lets it play nicely with our <base> tag. - If rewriteHashlinks = 'php' then, a piece of PHP script will be inserted before the hash links: "<?php echo $_SERVER['REQUEST_URI']; ?>". This is useful if you're generating a page that will be saved to a .php file and may be accessed from different URLs.

public static Mixed
# getOption( String $optionName )

Parameters

$optionName
String

Returns

Mixed
public static
# topLevel( )
public
# dontRewriteHashlinks( )

Call this to disable rewriting of links. This is useful in Ajax applications. It returns the SSViewer objects, so that you can call new SSViewer("X")->dontRewriteHashlinks()->process();

Call this to disable rewriting of links. This is useful in Ajax applications. It returns the SSViewer objects, so that you can call new SSViewer("X")->dontRewriteHashlinks()->process();

public
# exists( )
public static string
# getTemplateFile( string $identifier )

Searches for a template name in the current theme:

  • themes/mytheme/templates
  • themes/mytheme/templates/Includes

Falls back to unthemed template files.

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.

Parameters

$identifier
string
$identifier A template name without '.ss' extension or path.

Returns

string
Full system path to a template file

Used by

SSViewer::getTemplateContent()
public static string
# getTemplateFileByType( string $identifier, string $type )

Parameters

$identifier
string
$identifier A template name without '.ss' extension or path
$type
string
$type The template type, either "main", "Includes" or "Layout"

Returns

string
Full system path to a template file
public static string
# getTemplateContent( string $identifier )

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

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

Parameters

$identifier
string
$identifier A template name without '.ss' extension or path.

Returns

string
content of template

Uses

SSViewer::getTemplateFile()
public static
# flush_template_cache( )

Clears all parsed template files in the cache folder.

Clears all parsed template files in the cache folder.

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

public String
# process( ViewableData $item, SS_Cache $cache = null )

The process() method handles the "meat" of the template processing. It takes care of caching the output (via SS_Cache), as well as replacing the special "$Content" and "$Layout" placeholders with their respective subtemplates. The method injects extra HTML in the header via Requirements::includeInHTML().

The process() method handles the "meat" of the template processing. It takes care of caching the output (via SS_Cache), as well as replacing the special "$Content" and "$Layout" placeholders with their respective subtemplates. The method injects extra HTML in the header via Requirements::includeInHTML().

Note: You can call this method indirectly by ViewableData->renderWith().

Parameters

$item
ViewableData
$item
$cache
SS_Cache
$cache Optional cache backend

Returns

String
Parsed template output.
public static
# parseTemplateContent( mixed $content, mixed $template = "" )
public
# templates( )

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'

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'

public
# setTemplateFile( string $type, string $file )

Parameters

$type
string
$type "Layout" or "main"
$file
string
$file Full system path to the template file
public static
# get_base_tag( mixed $contentGeneratedSoFar )

Return an appropriate base tag for the given template. It will be closed on an XHTML document, and unclosed on an HTML document.

Return an appropriate base tag for the given template. It will be closed on an XHTML document, and unclosed on an HTML document.

Parameters

$contentGeneratedSoFar
mixed
$contentGeneratedSoFar The content of the template generated so far; it should contain the DOCTYPE declaration.

Magic methods summary

Properties summary

protected static boolean $source_file_comments
#

$source_file_comments

$source_file_comments

protected boolean $rewriteHashlinks
#
protected static string $current_theme
#
protected static string $current_custom_theme
#
protected static array $options
#
protected static array $topLevel
#

Comments

Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.
blog comments powered by Disqus
SilverStripe 2.4 API Docs API documentation generated by ApiGen 2.8.0