Skip to content

Missing way to use control constants as snippet/snippetArea name #141

@mstefan21

Description

@mstefan21

We are using control constants to define control names for better orientation in the project code. Unfortunately currently there is no way to do same thing with the snippet. For example:

namespace Vendor\App;

class ExampleForm extends Nette\Application\UI\Form
{

    const CONTROL_SUBMIT = 'submit';
    const SNIPPET_FORM = 'form';

    public function __construct()
    {
        $this->addSubmit(self::CONTROL_SUBMIT, 'submit')
            ->onClick[] = array($this, 'handleSubmit');
    }

    public function handleSubmit(SubmitButton $button)
    {
        $this->onSubmit($button);
        $this->redrawControl(self::SNIPPET_FORM);
    }

}
{form $control::CONTROL_FORM}
    <div n:snippet="$form::SNIPPET_FORM">
        {input $form::CONTROL_SUBMIT}
    </div>
{/form}

or

{form \Vendor\App\ExampleControl::CONTROL_FORM}
    <div n:snippet="\Vendor\App\ExampleForm::SNIPPET_FORM">
        {input \Vendor\App\ExampleForm::CONTROL_SUBMIT}
    </div>
{/form}

This example unfortunately will throw the following exception:
Dynamic snippets are allowed only inside static snippet/snippetArea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions