Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Static Publisher


Go to End


3 Posts   2923 Views

Avatar
kheeteck

Community Member, 7 Posts

26 June 2009 at 5:37pm

Hi

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
### SILVERSTRIPE START ###
RewriteEngine On

## CONFIG FOR TEST/LIVE ENVIRONMENTS

# 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 CONFIG

# 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]
### SILVERSTRIPE END ###

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 !

Thanks

Avatar
plautzer

Community Member, 10 Posts

5 February 2010 at 10:40am

Hi,

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?

Avatar
ChrisBryer

Community Member, 95 Posts

25 February 2010 at 9:19am

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