Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Using collection as options for select

Started by P. Fighter 9 years ago · 2 replies · 1186 views
9 years ago

Ho @punchfighter

I will create a static function in my theme ( Mytheme.php)

Example, of course you can make your own

PHP
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:

YAML
header.taxonomy.myselect:
   type: select
   label: My Label
   multiple: true
   data-options@: ['\Grav\Theme\Themename::getPageTitle', '@page.modular', '/path']
   validate:
      type: commalist

See Here for Data options

Hope it helps

👍 1
9 years ago

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.

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Anna, 2 days ago
2 53 16 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 82 16 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 186 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 379 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 595 2 months ago