How would I go about populating a page template select field with a collection?
last edited 03/22/18 by P. Fighter
Community guidelines
Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.
How would I go about populating a page template select field with a collection?
Ho @punchfighter
I will create a static function in my theme ( Mytheme.php)
Example, of course you can make your own
public static function getPageTitle($collection_options, $path)
{
$grav = Grav::instance();
$page = $grav['page'];
$collection = $page->evaluate([$collection_options => $path]);
$titles = [];
foreach ($collection as $item) {
$titles[$item->title()] = $item->title();
}
return $titles;
}
Then call it in your Blueprints:
header.taxonomy.myselect:
type: select
label: My Label
multiple: true
data-options@: ['\Grav\Theme\Themename::getPageTitle', '@page.modular', '/path']
validate:
type: commalist
Hope it helps
Thanks. Your namespace seems to bork the thing, though.
Declaring $grav absolutely, as $grav = \Grav\Common\Grav::instance(); does the trick.
I think I need to brush up on namespace syntax because my brain is marinara right now.
Log in to reply.
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 13 | 1140 | 4 months ago | ||
| 0 | 63 | 5 months ago | ||
| 9 | 138 | 6 months ago | ||
| 7 | 114 | 7 months ago | ||
| 10 | 132 | 7 months ago |