SSViewer
class SSViewer implements Flushable (View source)
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=1 on your URL, it will force the template to be recompiled.
Properties
protected | bool | $rewriteHashlinks | ||
protected | bool | $includeRequirements | ||
protected | TemplateParser | $parser | ||
protected static | $topLevel | |||
protected | Zend_Cache_Core | $partialCacheStore |
Methods
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
Create a template from a string instead of a .ss file
Returns an array of theme names present in a directory.
Traverses the given the given class context looking for templates with the relevant name.
Returns true if at least one of the listed templates exists.
Call this to disable rewriting of links. This is useful in Ajax applications.
Clears all parsed template files in the cache folder.
Set the cache object to use when storing / retrieving partial cache blocks.
Get the cache object to use when storing / retrieving partial cache blocks.
An internal utility function to set up variables in preparation for including a compiled template, then do the include
The process() method handles the "meat" of the template processing.
Execute the given template, passing it the given data.
Execute the evaluated string, passing it the given data.
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'
Return an appropriate base tag for the given template.
Details
static
set_source_file_comments(bool $val)
deprecated
deprecated
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
static bool
get_source_file_comments()
deprecated
deprecated
No description
static
flush()
Triggered early in the request when someone requests a flush.
static SSViewer
fromString(string $content, bool|void $cacheTemplate = null)
Create a template from a string instead of a .ss file
static
set_theme(string $theme)
deprecated
deprecated
No description
static string
current_theme()
deprecated
deprecated
No description
static string
get_theme_folder()
Returns the path to the theme folder
static array
get_themes(string $path = null, bool $subthemes = false)
Returns an array of theme names present in a directory.
static string
current_custom_theme()
deprecated
deprecated
No description
static array
get_templates_by_class($className, $suffix = '', $baseClass = null)
Traverses the given the given class context looking for templates with the relevant name.
__construct(string|array $templateList, TemplateParser $parser = null)
No description
setParser(TemplateParser $parser)
Set the template parser that will be used in template generation
TemplateParser
getParser()
Returns the parser that is set for template generation
static bool
hasTemplate(array $templates)
Returns true if at least one of the listed templates exists.
static
setOption(string $optionName, mixed $optionVal)
deprecated
deprecated
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
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.
static mixed
getOption($optionName)
deprecated
deprecated
No description
static
topLevel()
No description
static protected Zend_Cache_Core
defaultPartialCacheStore()
No description
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();
exists()
No description
static string
getTemplateFileByType(string $identifier, string $type)
No description
static
flush_template_cache(bool $force = false)
Clears all parsed template files in the cache folder.
Can only be called once per request (there may be multiple SSViewer instances).
static
flush_cacheblock_cache(bool $force = false)
Clears all partial cache blocks.
Can only be called once per request (there may be multiple SSViewer instances).
setPartialCacheStore(Zend_Cache_Core $cache)
Set the cache object to use when storing / retrieving partial cache blocks.
Zend_Cache_Core
getPartialCacheStore()
Get the cache object to use when storing / retrieving partial cache blocks.
includeRequirements($incl = true)
Flag whether to include the requirements in this response.
protected string
includeGeneratedTemplate(string $cacheFile, SS_Object $item, array|null $overlay, array|null $underlay, SS_Object $inheritedScope = null)
An internal utility function to set up variables in preparation for including a compiled template, then do the include
Effectively this is the common code that both SSViewer#process and SSViewer_FromString#process call
HTMLText
process(ViewableData $item, array|null $arguments = null, SS_Object $inheritedScope = 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().
Note: You can call this method indirectly by ViewableData->renderWith().
static string
execute_template(string $template, mixed $data, array $arguments = null, $scope = null)
Execute the given template, passing it the given data.
Used by the <% include %> template tag to process templates.
static string
execute_string(string $content, mixed $data, array $arguments = null)
Execute the evaluated string, passing it the given data.
Used by partial caching to evaluate custom cache keys expressed using template expressions
parseTemplateContent($content, $template = "")
No description
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'
setTemplateFile(string $type, string $file)
No description
static
get_base_tag($contentGeneratedSoFar)
Return an appropriate base tag for the given template.
It will be closed on an XHTML document, and unclosed on an HTML document.