Blog Sections Open

Building a NewsController with DLMenu, DocLister, and Blade in Evolution CMS

A practical controller guide for building a news section with DLMenu, DocLister, Blade partials, and paginator data.

This gist is worth preserving as a standalone guide because it shows a very practical middle ground between classic snippet-driven templates and a fuller controller-based Evo project. The pattern is simple but strong: use DLMenu for section navigation, use DocLister to fetch the listing, reshape the collection in PHP, and pass the final arrays into Blade partials.

That makes the controller more than a code sample. It is a reusable pattern for news sections, blogs, and other editorial listings where you want cleaner data preparation without rewriting your whole project around a new stack.

Controller pattern

<?php
namespace EvolutionCMS\Odkb\Controllers;

class NewsController extends BaseController {
    public function render() {
        $this->data['newsmenu'] = json_decode($this->evo->runSnippet('DLMenu', [
            'parents' => 69,
            'maxDepth' => 1,
            'api' => 1,
        ]), true)[0];

        $this->data['newsitems'] = $this->DocLister([
            'depth' => 2,
            'display' => 12,
            'paginate' => 'pages',
            'tvList' => 'important',
            'saveDLObject' => '_DL'
        ]);
    }

    public function DocLister($data) {
        $this->evo->runSnippet('DocLister', $data);
        $_DL = $this->evo->getPlaceholder('_DL');
        $docs = $_DL->docsCollection()
            ->map(function(array $doc){
                $doc['date'] = $this->evo->runSnippet('aDate', [
                    'date' => $doc['createdon'],
                    'date2' => $doc['publishedon']
                ]);
                return $doc;
            })
            ->toArray();

        $paginator = $_DL->getExtender('paginate');
        return [
            'docs' => $docs,
            'pages' => [
                'first' => 1,
                'last' => $paginator->totalPage(),
                'current' => $paginator->currentPage(),
                'docs' => $paginator->totalDocs()
            ]
        ];
    }
}

Blade output pattern

<div class="news__block">
@foreach($newsitems['docs'] as $item)
    @include('partials.newsitem', ['item' => $item])
@endforeach
</div>
<nav class="pagination">
    @include('partials.paginate', ['paginate' => $newsitems['pages']])
</nav>

Why this pattern works well

  • it keeps menu data, listing data, and pagination metadata separate but easy to render together
  • it lets you enrich each DocLister row before it reaches the Blade template
  • it gives Blade partials clean arrays instead of forcing presentation logic back into snippets

Where to use it

  • news sections with category menus
  • blog indexes with date formatting and pagination
  • controller-based Evo projects that still want to reuse DocLister instead of replacing it entirely

Source: gist. Related code: NewsController + Blade snippet.

Newer post

The Ideal Store: Planning a Better Evolution CMS Commerce Stack

A commerce editorial about what a stronger Evolution CMS store stack should include beyond the basic cart and checkout feature set.

Older post

Passing Placeholder Values into a Custom Snippet

A small debugging guide for passing placeholder output into custom snippets and avoiding empty values caused by parser timing or quoting mistakes.