Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Using collection as options for select

Started by P. Fighter 8 years ago · 2 replies · 844 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 Ton Haarmans, 5 years ago
13 1139 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 137 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 112 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 131 7 months ago