Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Using collection as options for select

Started by P. Fighter 9 years ago · 2 replies · 1075 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 Japhy, 2 weeks ago
2 264 4 days ago
Forms & Blueprints · by FrViPofm, 4 weeks ago
5 326 4 weeks ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2317 8 months ago
Forms & Blueprints · by Hugo Oliveira, 9 months ago
0 780 9 months ago
Forms & Blueprints · by Flachy Joe, 10 months ago
9 868 10 months ago