The code below works only for Blog template and snippets. Now my scenario is i want to display the articles in other template and snippet.
Can someone help me pls. Heres my controller
return function($site, $pages, $page) {
$perpage = $page->perpage()->int();
$articles = $page->children()
->visible()
->flip()
->paginate(($perpage >= 1)? $perpage : 9)->sortBy('date', 'desc', 'time', 'desc');
return [
'articles' => $articles,
'pagination' => $articles->pagination()
];
if(kirby()->request()->ajax()){
// in ajax request - this snippet will be returned by the server.. the site and page object should be redeclared in here...
// in ajax, the global objects are unknown
exit(snippet('blog', compact('pagination'), true));
} else {
return compact('pagination');
}