Version: current

# Class SSViewer

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:

    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
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` 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`` SSViewer
`public static` | # `set_theme( string $theme )` #### Parameters $theme string $theme
`public static string` | # `current_theme( )` #### Returns `string` string
`public static string` | # `current_custom_theme( )` #### Returns `string` string
`public` | # `__construct( string|array $templateList )` Pass the SilverStripe template to be used. Pass the SilverStripe template to be used. #### Parameters $templateList string|array $templateList If passed as a string with .ss extension, used as the "main" template
`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` | # `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` | # `process( mixed $item, mixed $cache = null )` The process() method handles the "meat" of the template processing. The process() method handles the "meat" of the template processing.
`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 $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 | #

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -