Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to never cache twig. #1244

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ form:
validate:
type: bool

pages.never_cache_twig:
type: toggle
label: PLUGIN_ADMIN.NEVER_CACHE_TWIG
help: PLUGIN_ADMIN.NEVER_CACHE_TWIG_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

pages.frontmatter.process_twig:
type: toggle
label: PLUGIN_ADMIN.FRONTMATTER_PROCESS_TWIG
Expand Down
24 changes: 24 additions & 0 deletions system/blueprints/pages/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,30 @@ form:
twig: Twig
use: keys

header.twig_first:
type: toggle
toggleable: true
label: PLUGIN_ADMIN.TWIG_FIRST
help: PLUGIN_ADMIN.TWIG_FIRST_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

header.never_cache_twig:
type: toggle
toggleable: true
label: PLUGIN_ADMIN.NEVER_CACHE_TWIG
help: PLUGIN_ADMIN.NEVER_CACHE_TWIG_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

header.child_type:
type: select
toggleable: true
Expand Down
1 change: 1 addition & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pages:
markdown: true # Process Markdown
twig: false # Process Twig
twig_first: false # Process Twig before markdown when processing both on a page
never_cache_twig: false # Only cache content, never cache twig processed in content (incompatible with `twig_first: true`)
events:
page: true # Enable page level events
twig: true # Enable Twig level events
Expand Down
60 changes: 43 additions & 17 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,38 +572,64 @@ public function content($var = null)
$twig_first = isset($this->header->twig_first) ? $this->header->twig_first : $config->get('system.pages.twig_first',
true);

// never cache twig means it's always run after content
$never_cache_twig = isset($this->header->never_cache_twig) ? $this->header->never_cache_twig : $config->get('system.pages.never_cache_twig',
false);

// if no cached-content run everything
if ($this->content === false || $cache_enable === false) {
$this->content = $this->raw_content;
Grav::instance()->fireEvent('onPageContentRaw', new Event(['page' => $this]));
if ($never_cache_twig) {
if ($this->content === false || $cache_enable === false) {
$this->content = $this->raw_content;
Grav::instance()->fireEvent('onPageContentRaw', new Event(['page' => $this]));

if ($twig_first) {
if ($process_twig) {
$this->processTwig();
}
if ($process_markdown) {
$this->processMarkdown();
}

// Content Processed but not cached yet
Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this]));

} else {
if ($process_markdown) {
$this->processMarkdown();
if ($cache_enable) {
$this->cachePageContent();
}
}

// Content Processed but not cached yet
Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this]));
if ($process_twig) {
$this->processTwig();
}

} else {
if ($this->content === false || $cache_enable === false) {
$this->content = $this->raw_content;
Grav::instance()->fireEvent('onPageContentRaw', new Event(['page' => $this]));

if ($process_twig) {
$this->processTwig();
if ($twig_first) {
if ($process_twig) {
$this->processTwig();
}
if ($process_markdown) {
$this->processMarkdown();
}

// Content Processed but not cached yet
Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this]));

} else {
if ($process_markdown) {
$this->processMarkdown();
}

// Content Processed but not cached yet
Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this]));

if ($process_twig) {
$this->processTwig();
}
}
}

if ($cache_enable) {
$this->cachePageContent();
if ($cache_enable) {
$this->cachePageContent();
}
}
}

Expand Down