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

Rule: Curly braces should not be used in PHTML files #16

Closed
renttek opened this issue Apr 29, 2018 · 4 comments
Closed

Rule: Curly braces should not be used in PHTML files #16

renttek opened this issue Apr 29, 2018 · 4 comments

Comments

@renttek
Copy link

renttek commented Apr 29, 2018

Curly braces should not be used in PHTML files.

Bad:

<?php
if ($block->getFooList()) {
    foreach ($block->getFooList() as $foo) {
?>
        <!-- Template stuff -->
<?php
    }
}
?>

Better (Proposal 1):

<?php
if ($block->getFooList()):
    foreach ($block->getFooList() as $foo):
?>
        <!-- Template stuff -->
<?php
    endforeach;
endif;
?>

Better (Proposal 2):

<?php if ($block->getFooList()) ?>
    <?php foreach ($block->getFooList() as $foo): ?>
        <!-- Template stuff -->
    <?php endforeach; ?>
<?php endif; ?>

(Source: https://twitter.com/jissereitsma/status/990301162090975232)

@jissereitsma
Copy link
Contributor

Thanks @renttek . You mention that "curly braces should not be used in PHTML templates". Could you elaborate a bit on why this is the case? I understand that this could be a best practice, but we first need to summarize why this actually needs to be a best practice.

@navarr
Copy link

navarr commented Apr 30, 2018

I also prefer curly braces in PHTML when (and only when) the start and end is in the same PHP block, for example, if statements and variable assignment at the top of the template file.

@schmengler
Copy link
Collaborator

@navarr that sounds good. What about: "opening and closing braces must be within the same <?php ... ?> block"?

@schmengler
Copy link
Collaborator

Closed in favor of new issue #41

@schmengler schmengler removed the on agenda of hangout This issue will be discussed in the next open hangout label Jun 4, 2018
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