This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

osarzola
osarzola

I am trying to acomplish that, but how can i "tweak" the render function and the routing to do this?

Please, wich is the best way to do this?

/**
     * Creates a CMS page from a static page and configures it.
     * @param string $url Specifies the static page URL.
     * @return \Cms\Classes\Page Returns the CMS page object or NULL of the requested page was not found.
     */
    public function initCmsPage($url) {
        $router = new Router($this->theme);
        $page = $router->findByUrl($url);

        if (!$page) {
            return null;
        }
        $p = new Page();
        $p->markup = $page->content_html;
        return $p;
    }

My Router return actually a Eloquent Model

$page = $router->findByUrl($url);

I copy the Static Pages Controller and tried to do this but does not works :( any clue?

Last updated

osarzola
osarzola

I "workaround" this way.

1.- i created a layout named container with a "dirty trick" that allows five slash levels

description = "Pages Template"

[OsPage]
==
<!DOCTYPE html>
<html>
<head>
    <title>{{ this.page.title }}</title>
    <meta charset="UTF-8">
    {% partial "favicons" %}
    {% styles %}
    <link href="{{ [
            'assets/css/theme.css'
        ]|theme }}" rel="stylesheet">
</head>
<body id="top">
{% partial "header" %}

<main role="main">
    <div class="container">
        {% component 'OsPage' %}
    </div>
</main>
{% partial "footer" %}

<script src="{{[
'@jquery','assets/js/src/vendor/bootstrap.min.js','assets/js/src/vendor/carousel.min.js'
]|theme }}"></script>
{% scripts %}
{% framework extras %}
<script src="{{['assets/js/src/app.js']|theme }}"></script>
</body>
</html>

2.- Create a page that Holds the component

url = "/:uri/:level1?/:level3?/:level4?/:level5?"
layout = "container"
is_hidden = 0
==

3.- Init my Plugin like oc-autumn-pages (thank you)

public function init()
    {
        $this->data = $this->loadData();
        if(!$this->data){

            return Response::make($this->controller->run('404'), 404);
        }
        $this->page['title'] = $this->data->title;
        $this->page->meta_description = $this->data->meta_description;
        $this->page->meta_keywords = $this->data->meta;
    }

    public function onRender()
    {
        $this->page['title'] = $this->data->title;
    }

    protected function loadData()
    {
        return Sitio::where('slug', '=', $_SERVER['REQUEST_URI'])->first(); //TODO: Fix Route implementation
    }

4.- Print the content in the component default.htm view

{% set page = __SELF__.data %}
{{ page.content_html| raw }}

5.- Now you can create free pages saved in a database without prefixed page container: like /blog/dsadsad

Examples:

  • /newfancypage
  • /another/cool/page
  • /hello/iam/another/page

All that pages are saved in a database table managed via plugin:

Os Pages Preview

Last updated

phplee
phplee

Hi Osarzola

Did you manage to get this working. would love the static page plugin to actually use a database.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.