Technical notes about OctoberCMS a Laravel CMS by inetis team, a Swiss webagency

<- Back

Render the content of subpages

Posted on by

If you are building a onepage template with octoberCMS, it is a good idea to manage blocks with the Page plugin. But how can you render them on the final page without losing snippet functionality ?

The first solution is to use a plugin https://octobercms.com/plugin/jwilson8767-subpages . This plugin allow you to pass the name of a page in parameter and display all the subpages.

url = "/"
title = "One page exemple"
layout = "default"

[subpages]
page='/mainpage'

==
//php code block
==
<div class="container">
    {% component 'subpages' %}
</div>

Another solution that does not require a plugin is to use the RainLab\Pages\Classes\Page class. Don't forget to use a raw filter for the content of your page, because it contains HTML tags.

use RainLab\Pages\Classes\Page;

function onStart()
{
    $file = 'accueil-1.htm';
    $page = Page::find($file);
    $this['home1Title'] = $page->title;    
    $this['home1'] = $page->getProcessedMarkup();  
}
<div class="container">
            <h2>{{ home1Title }}</h2>
            {{ home1|raw }}
</div>