Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LHavlicek opened this issue Oct 21, 2022 · 0 comments
Closed

Comments

@LHavlicek
Copy link

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.

@dg dg closed this as completed Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants