Skip to content
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

surprising syntax error due to control flow syntax in template #1933

Open
bkerin opened this issue Mar 28, 2022 · 3 comments
Open

surprising syntax error due to control flow syntax in template #1933

bkerin opened this issue Mar 28, 2022 · 3 comments

Comments

@bkerin
Copy link

bkerin commented Mar 28, 2022

  • Mojolicious version: pretty recent I think
  • Perl version: 5.28
  • Operating system: debian linux

Steps to reproduce the behavior

It's probably known and unavoidable but this syntax in a template:

      % if ( $error ) {

        <%= $error %>

      % }

      % else {

      }

Causes a syntax error:

syntax error at template sign_in.html.ep line 27, near ";
else"
syntax error at template sign_in.html.ep line 82, near "} $_O "
Global symbol "$_O" requires explicit package name (did you forget to declare "my $_O"?) at template sign_in.html.ep line 82.
22
23
<%= $error %>
24
25
% }
26
27
% else {
28

Just removing the blank line between % } and % else { fixes it:

      % }
      % else {

Some note about this behavior in https://docs.mojolicious.org/Mojolicious/Guides/Rendering
or something might be good

Expected behavior

works like perl

Actual behavior

EXPLAIN WHAT HAPPENED INSTEAD HERE

@daleif
Copy link

daleif commented Mar 29, 2022

Interesting error. BTW might want to use % } at the end in the example as that is also an error, but not the interesting one here.

All the examples use % } else { so might never been tested, or might not he recommended syntax.

@guest20
Copy link

guest20 commented Mar 30, 2022

@bkerin. Your example has a blank line between % } and else { and that blank line turns into an output "a new line" in the transpiled(?) template.

If you stick a % at the front of that blank line, or omit it it'll work fine:

% if (...) { 
yes.
% }
% else {
nope.
% }

~~
A non-cuddled-else-enjoyer 

@kraih
Copy link
Member

kraih commented Mar 30, 2022

Indeed, a blank line in between code lines won't work. This is expected behaviour.

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

4 participants