I want to use a function call in my blueprints where I fetch the titles of all pages located in a directory, but I have no idea how to do this. The example in the tutorial fetches all paths, so I want to do something similar where I can define which directory (ie '/blog/' or '/filters/') as a parameter and then get a list of all children in my select input where selected it will save the title of the page to the markdown file.
Archive
I kind of solved this myself by adding below to my themename.php file.
I don't have much experience with PHP, doing mostly front-end, but this works perfectly and on first glance doesn't look hacky at all.
---php
use Grav\Common\Grav;
/**
- Get page titles returned.
-
@return array
*/
public static function getPageTitle($collection_options, $path)
{PHP$grav = Grav::instance(); $page = $grav['page']; $collection = $page->evaluate([$collection_options => $path]); $titles = []; foreach ($collection as $item) { $titles[$item->title()] = $item->title(); } return $titles;}
TXT
and then adding the method to my blueprint like this:
---yaml
header.taxonomy.functionality:
type: select
label: Functionalities
multiple: true
data-options@: ['\Grav\Theme\Themename::getPageTitle', '@page.modular', '/product/functionalities']
validate:
type: commalist
Log in to reply.
Suggested topics
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 0 | 1333 | 9 years ago | ||
| 2 | 924 | 9 years ago | ||
| 2 | 4055 | 9 years ago | ||
| 1 | 2938 | 9 years ago | ||
| 3 | 1111 | 9 years ago |