Ad

How To Dynamically Generate Page Links In October Cms

- 1 answer

I am trying to create a dynamically generated navmenu based on the pages created in the backend I thought I could use something like {% for page in pages %} to get a list of created pages I have read the documentation and I see you can use { '' |page } and { '' |app } which give the same value ie http://website/ but would like to get the list of all pages like the walker file in wordpress any idea how would achieve this.

==
<?php
use Cms\Classes\Theme;
use Cms\Classes\Page;

function onStart() {
   $currentTheme = Theme::getActiveTheme();
   $allPages = Page::listInTheme($currentTheme, true);
   $this['allPage'] = $allPages;
}
?>
==
<div class="lt-navbar navbar-fixed">
  <nav class="lt-no-background">
    <div class="nav-wrapper">
      <div class="lt-container container">
        <a target="_blank" rel="nofollow noreferrer" href="{{ 'home'|page }}" class="brand-logo white-text"><img src="{{ 'assets/img/pages/all/logo.png'|theme }}" width="177" height="55" title="Logo" alt="Logo"></a>
        <a target="_blank" rel="nofollow noreferrer" href="#" data-activates="mobile-menu" class="lt-mobile-toggle button-collapse"><i class="material-icons">menu</i></a>
        <ul>
            {% for page in pages %}
            <li><a target="_blank" rel="nofollow noreferrer" href="{{ page.baseFileName|page}}">{{page.title}}</a></li>
            {% endfor %}
</div>
    </div>
  </nav>
</div>
        </ul>
Ad

Answer

Yes you can. You can use Built in System classes for that

use Cms\Classes\Theme;
use Cms\Classes\Page;

Then to get all the pages within the current theme

$currentTheme = Theme::getActiveTheme();
$allPages = Page::listInTheme($currentTheme, true);

In code section

use Cms\Classes\Theme;
use Cms\Classes\Page;

function onStart() {
   $currentTheme = Theme::getActiveTheme();
   $allPages = Page::listInTheme($currentTheme, true);
   $this['allPage'] = $allPages;
}

In template

<ul>
{% for page in allPage %}
    <li>< a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ page.baseFileName|page}}">{{page.title}}</a></li>
{% endfor %}
</ul>

if any doubts please comment.

Ad
source: stackoverflow.com
Ad