On Wed, 8 Jun 2022 at 20:16, shinji igarashi <s...@sj-i.dev> wrote:

> > declare(ignore_newline_after_close_tag=false);
>
> Thanks for coming up with another idea!
>
> As others have already pointed out, disabling the closing tag from
> eating trailing newline throughout the file would be inconvenient if
> we want to use control statements in the template.
>
> However, we currently only have one closing tag, but we already
> have two opening tags. So, for example, if we use declare to disable
> the newline eating only when closing a PHP block started with `<?=',
> it can produce the desired output.
>
> <?php declare(ignore_newline_after_closing_short_tag=false) ?>
> <?php foreach ([1, 2, 3] as $item): ?>
> - <? = $item ?>
> <?php endforeach ?>
>
> I'm honestly not sure if adding a declare switch is better received
> than a new closing tag, though.
>
> Thanks!
>
> --
> Shinji Igarashi
>
> 2022年6月8日(水) 12:34 Sara Golemon <poll...@php.net>:
> >
> > On Tue, Jun 7, 2022 at 10:27 AM Robert Landers <landers.rob...@gmail.com>
> wrote:
> > > FWIW, I think it makes a lot of sense, having used golang's template
> > > language (not everyone is generating HTML with PHP). I think you may
> > > just be dealing with a vocal minority and it would be worth putting to
> > > an actual vote. Even if it fails, we'll learn something the next time
> > > someone wants to change something like this.
> > >
> >
> > While my gut response for the new end tag is in the "no" column, I do
> wonder if we can accommodate "non-html" scenarios in a broader (maybe more
> palatable?) way by assuming that if you want the newline to be respected on
> one line, you probably want it that way for the whole file.
> >
> > <?php
> > declare(ignore_newline_after_close_tag=false); // defaults to true, i.e
> existing behavior
> >
> > This would avoid any new syntax rules, but still provide the ability for
> php-as-template-engine to behave in the user's preferred mode.
> >
> > -Sara
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php


I'm just adding a few cents into this discussion for some inspiration. If
I'm not mistaken, the Twig template engine, for example, has such a
difference integrated in the output tag and the statement tag. The
statement tag ({% %}) behaves as PHP tag, it removes the newline character.
The outputting tag ({{ }}) adds a newline at the end.

See this: https://twigfiddle.com/pto9qx

More info about this here:
https://twig.symfony.com/doc/3.x/templates.html#whitespace-control

So, it is actually important to have such functionality in templates.

Reply via email to