Ad

OctoberCMS Get List Of Content Files

- 1 answer

Trying to get content files started with cont*

using :

Content::loadCached('theme', 'listOfContentFiles');

And getting an error. I can get one but not the list.

Ad

Answer

Seems there is no direct way of doing it, you can use this code to get list manually and filter it by your self

use Cms\Classes\Content;
use Cms\Classes\Theme;

$activeTheme =  Theme::getActiveTheme();
$instance = Content::inTheme($activeTheme);

$items = $instance->newQuery()->lists('fileName');

$loadedItems = [];
foreach ($items as $item) {

    // we need to manually filter data you can
    // add more logic here for sub directory parsing etc
    if(starts_with($item, 'cont_')) {
        $loadedItems[] = Content::loadCached($activeTheme, $item);
    }
}

dd($loadedItems);

// if you want to make it collection
$result = $instance->newCollection($loadedItems);

it will return you list of content files in active theme by our filter logic.

Ad
source: stackoverflow.com
Ad