Permalink
Browse files

Grav: Implement module caching

  • Loading branch information...
1 parent b76e02c commit 59f615c43c231b3fd301216cd8a5b58d4a2f8c49 @mahagr mahagr committed Jan 4, 2017
@@ -8,9 +8,13 @@
{% endblock %}
{% block module %}
- {% include [
- '@nucleus/content/' ~ segment.type ~ '/' ~ segment.options.type|default('default') ~ '.html.twig',
- '@nucleus/content/' ~ segment.type ~ '.html.twig',
- '@nucleus/content/unknown.html.twig']
- with { segment: {id: id, type: segment.type, subtype: segment.options.type, options: segment.options, attributes: segment.options.attributes }} %}
+ {% if segment.type in ['particle', 'spacer'] %}
+ {{ gantry.theme.renderContent({id: id, type: segment.type, subtype: segment.options.type, attributes: segment.options.attributes}) }}
+ {% else %}
+ {% include [
+ '@nucleus/content/' ~ segment.type ~ '/' ~ segment.options.type|default('default') ~ '.html.twig',
+ '@nucleus/content/' ~ segment.type ~ '.html.twig',
+ '@nucleus/content/unknown.html.twig']
+ with { segment: {id: id, type: segment.type, subtype: segment.options.type, options: segment.options, attributes: segment.options.attributes }} %}
+ {% endif %}
{% endblock %}
@@ -524,7 +524,7 @@ protected function prepareLayout(array &$items, $temporary = false, $sticky = fa
case 'spacer':
GANTRY_DEBUGGER && \Gantry\Debugger::startTimer($item->id, "Rendering {$item->id}");
- $item->content = $this->renderContent($item);
+ $item->content = $this->renderContent($item, ['prepare_layout' => true]);
// Note that content can also be null (postpone rendering).
if ($item->content === '') {
unset($items[$i]);
@@ -589,11 +589,16 @@ protected function prepareLayout(array &$items, $temporary = false, $sticky = fa
*
* Function is used to pre-render content.
*
- * @param object $item
+ * @param object|array $item
+ * @param array $options
* @return string|null
*/
- protected function renderContent($item)
+ protected function renderContent($item, $options = [])
{
+ if (is_array($item)) {
+ $item = (object) $item;
+ }
+
$gantry = static::gantry();
$subtype = $item->subtype;
@@ -627,6 +632,7 @@ protected function renderContent($item)
$cached = true;
$extra = ['_active_menu_item' => $active];
+ break;
}
}
@@ -648,13 +654,14 @@ protected function renderContent($item)
$document->appendHeaderTags($content['assets']);
}
}
+
if (!isset($html)) {
if (isset($file)) {
// Create new document context for assets.
$document->push();
}
- $context = $this->getContext(['segment' => $item, 'enabled' => 1, 'particle' => $particle, 'prepare_layout' => true]);
+ $context = $this->getContext(['segment' => $item, 'enabled' => 1, 'particle' => $particle] + $options);
$html = trim($this->render("@nucleus/content/{$item->type}.html.twig", $context));
if (isset($file)) {

0 comments on commit 59f615c

Please sign in to comment.