cms icon indicating copy to clipboard operation
cms copied to clipboard

Allow actionButton to be set as a template variable

Open leevigraham opened this issue 8 months ago • 0 comments

Description

Allows element index creation in a controller without the need for a template.

Example:

public function actionIndex(): Response
    {
        return $this
            ->renderTemplate('_layouts/elementindex', [
                'elementType' => Organisation::class,
                'title' => Craft::t('_kraftwerk', 'Organisations'),
                'selectedSubnavItem' => 'organisations',
                'crumbs' => [
                    [
                        'label' => Craft::t('_kraftwerk', 'Kraftwerk'),
                        'url' => '_kraftwerk',
                    ],
                    [
                        'label' => Craft::t('_kraftwerk', 'Organisations'),
                        'url' => '_kraftwerk/organisations',
                    ]
                ],
                'actionButton' => Html::tag(
                    'a',
                    Craft::t('_kraftwerk', 'New Organisation'),
                    [
                        'href' => UrlHelper::actionUrl('elements/create', [
                            'elementType' => Organisation::class,
                        ]),
                        'class' => 'btn submit add icon',
                        'data-icon' => 'plus',
                    ]),
            ]);
    }

leevigraham avatar Jun 11 '25 05:06 leevigraham