Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Static Publisher

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1808 Views
  • kheeteck
    Community Member
    7 Posts

    Static Publisher Link to this post


    I have turned on the static publisher by adding this code to my _config.php

    Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')");

    And also in my .htaccess

    Added the following

    ### Replaced with new directives to support static publisher
    # http://doc.silverstripe.com/doku.php?id=staticpublisher
    RewriteEngine On


    # Cached content - live webserver
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} /(.*[^/])/?$
    RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /cache/%1.html [L]

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /cache/index.html [L]


    # Dynamic content
    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

    And in my Page.php

    Added the following functions
    function allPagesToCache() {
    // Get each page type to define its sub-urls
    $urls = array();

    // memory intensive depending on number of pages
    $pages = DataObject::get("SiteTree");

    foreach($pages as $page) {
    $urls = array_merge($urls, (array)$page->subPagesToCache());

    // add any custom URLs which are not SiteTree instances
    $urls[] = "sitemap.xml";

    return $urls;
    * Get a list of URLs to cache related to this page
    function subPagesToCache() {
    $urls = array();

    // add current page
    $urls[] = $this->Link();

    // cache the RSS feed if comments are enabled
    if ($this->ProvideComments) {
    $urls[] = Director::absoluteBaseURL() . "pagecomment/rss/" . $this->ID;

    return $urls;

    function pagesAffectedByChanges() {
    return $this->allPagesToCache(); // added line
    // $urls = $this->subPagesToCache();
    // if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
    // return $urls;

    However, i realized that after the cache is turned on, when i access the page, the submenu links are not working correctly

    for the blankcandy and evergreenz themes.

    For eg, if i try to select any items on the submenu, the highlighted link does not displayed correctly when i switch to another submenu item.

    This problem does not occurs if the cache is turn off.

    Anyone got any idea on how to solve that?

    Greatly appreciated !


  • plautzer
    Community Member
    7 Posts

    Re: Static Publisher Link to this post


    I have the same problem with the submenu.

    The class "current" is always set to the first link in all subpages:

    <li class="current"><a href="#" >Link1</a></li>
    <li class="link"><a href="#" >Link2</a></li>
    <li class="link"><a href="#" >Link3</a></li>

    Does anyone know how to fix this?


  • ChrisBryer
    Community Member
    95 Posts

    Re: Static Publisher Link to this post

    I have the same problem, and would love to hear any suggestions anyone may have.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.