Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Using collection as options for select

Started by P. Fighter 8 years ago · 2 replies · 1017 views
8 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
8 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 FrViPofm, 4 days ago
5 85 4 days ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2113 7 months ago
Forms & Blueprints · by Hugo Oliveira, 8 months ago
0 597 8 months ago
Forms & Blueprints · by Flachy Joe, 9 months ago
9 690 9 months ago
Forms & Blueprints · by Augustus, 10 months ago
7 737 10 months ago