Skip to content

Create n:name tag/macro form in Latte 3 directly in HTML <form> tag #291

@LHavlicek

Description

@LHavlicek

Bridge for Latte 3, NNameNode

Move variable assignment $form = $this->global->formsStack[] = $this->global->uiControl['formForm'] directly into the HTML <form> tag in Latte 3 seems unfortunate to me. Apart from taking advantage of the fact that the variable is created before the tag itself (it could be conditioned based on some form property, for example), this clashes with the n:tag-if condition set on the form. There is a crash rendering of the termination tag echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false), where it reaches into $this->global->formsStack, but it doesn't exist because the creation of the form tag is conditional and doesn't happen at all.

For a better understanding, see the script generated into PHP using <form n:tag-if="$someCondition" n:name="formForm">

$ʟ_tag[0] = ''; if ($someCondition) /* line 20 */ { echo '<'; echo $ʟ_tmp = ('form'); $ʟ_tag[0] = '</' . $ʟ_tmp . '>' . $ʟ_tag[0]; $form = $this->global->formsStack[] = $this->global->uiControl['formForm'] /* line 20 */; echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false) /* line 20 */; echo '>'; } ... echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) /* line 20 */; echo $ʟ_tag[0]; 

Possible Solution

I suggest moving the assignment $form = $this->global->formsStack[] = $this->global->uiControl['formForm'] back before the HTML form tag as in Latte 2.

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