Skip to content

Add Best Practice guideline for partials/include #8608

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
wants to merge 2 commits into from

Conversation

timonf
Copy link
Contributor

@timonf timonf commented Nov 9, 2017

Hi there,

I was wondering if there is no Best Practice guide for partials/includes. So I would recommend to use a single prefixed underscore to determine such partials easily like in the Symfony demo application: https://github.com/symfony/demo/tree/master/templates/blog

I saw often other solutions like @SomeBundle:Partials/post_form.html.twig. But I like the approach from the Symfony demo application, so it should be a Best Practice guideline :)

Regards,
Timon

@wouterj wouterj added this to the 2.7 milestone Nov 12, 2017
@wouterj
Copy link
Member

wouterj commented Nov 12, 2017

👍 I like it.

/cc @javiereguiluz please share your thoughts on this as you're the best practices master :)

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this proposal! the leading underscore has been an unofficial best practice for more than 12 years (since symfony 1) so it's time to make it official!

If I may, I'd like to propose some minor rewordings to this proposal:

.. best-practice::

    Prefix the file name of partial templates with an underscore.

You often want to reuse template code using the ``include()`` function to avoid
redundant code. To better differentiate those partials in the filesystem, you
should prefix their file names with a single underscore (e.g. ``_footer.html.twig``).

Thanks!

@weaverryan
Copy link
Member

I like it! Thank you Timon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants