Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use default_path instead of paths for Twig and Translator config #434

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

Merged
3 commits merged into from
Sep 8, 2018

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Jul 11, 2018

Q A
License MIT

Fix #416 (comment)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Pull request passes validation.

@xabbuh
Copy link
Member

xabbuh commented Jul 12, 2018

Is this really a good idea? Showing the paths option has the advantage that developers can easily discover where to add new paths. Now they may change the setting here thus overriding the default value coming from Symfony core which would then in turn change the behaviour of the app.

@javiereguiluz
Copy link
Member

I agree with Christian. I've changed the paths option of Twig in lots and lots of projects. Not sure if for others is common too ... but if it is, this change makes it harder to do that.

@Pierstoval
Copy link
Contributor

For new projects it might not be that common, as templates should still be stored under templates/

@fabpot
Copy link
Member

fabpot commented Jul 12, 2018

I would really be surprised if many people were overriding the paths. I cannot even think of one good reason to do that. But I understand the point. But:

  • if one changes the default_path, they will realized really fast that it breaks everything.

  • we try to not have all possible options in config files, meaning that we don't want to replace documentation here.

@yceruto
Copy link
Member Author

yceruto commented Jul 12, 2018

Redefining the default path again in twig.paths is not a good idea either, people might think that changing it they're moving the default template dir to another place, and that's not true, they might be surprised why templates/ dir is still working (if it exists)... Edit: and why for example debug:translation and translation:update commands don't work (which aren't compatible with all Twig paths, only the default ones)

@stof
Copy link
Member

stof commented Jul 12, 2018

Registering the existing default path in paths has another drawbacl: it means the path gets registered twice (as the default path is still registered), which was leading to bug reports about paths appearing twice in error messages

@yceruto
Copy link
Member Author

yceruto commented Aug 7, 2018

@stof That means you agree with this change, right? Could I get the last approval then?

@javiereguiluz
Copy link
Member

Related to this, someone asked about this yesterday on Slack:

What are the Twig class that are in charge to look for templates in directories?
I'd like to customize them to add some logic (go look inside this folder, then
another one, then take default behaviour)

They replied him:

twig:
    paths: ['%kernel.project_dir%/templates/plymouth', '%kernel.project_dir%/templates']

And he said:

thanks I thought i was going to write a TemplateGuesser


Apart from this, I understand what you say about default_path being defined twice. But don't you think the real problem is defining default_path itself? Not sure if possible but:

  1. We could add a super simple condition that checks if default_path is already in paths and remove it to avoid duplications.
  2. We could remove default_path and just use paths. If you absolutely need a default path, make it the first (or the last) element of paths?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Pull request passes validation.

@yceruto
Copy link
Member Author

yceruto commented Aug 9, 2018

if changing this configuration is really frequent and useful then it has won the place to appear by default. How does this look now?

@@ -1,4 +1,6 @@
twig:
# additional templates paths
Copy link
Member

Choose a reason for hiding this comment

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

additional template paths

@@ -1,6 +1,8 @@
framework:
default_locale: '%locale%'
translator:
# additional translations paths
Copy link
Member

Choose a reason for hiding this comment

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

additional translation paths

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Pull request passes validation.

@yceruto
Copy link
Member Author

yceruto commented Sep 4, 2018

symfony/symfony#27764 (comment) it's another reason to make this change. Setting the default path in Twig paths doesn't excludes the bundles/ directory on cache warmup and the overridden templates are cached using the wrong template name.

- '%kernel.project_dir%/translations'
# additional translation paths
#paths: []
default_path: '%kernel.project_dir%/translations'
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure default_path works here ? IIRC, it is a Symfony 3.4+ feature, while this recipe applies to 3.3+

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I'm following the same approach that @nicolas-grekas in the previous PR:

#416 (comment) (3.3 is EOLed so we don't really care for it)

Copy link
Member

Choose a reason for hiding this comment

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

a recipe is for new projects 99%, and no new project will use this recipe ever (or at least we don't care IMHO)

Copy link
Member

Choose a reason for hiding this comment

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

but then, it would be better to migrate this recipe to be 3.4+ and have no recipe at all for 3.3, than to have a 3.3+ recipe triggering an error on 3.3

@@ -1,7 +1,8 @@
framework:
default_locale: '%locale%'
translator:
paths:
- '%kernel.project_dir%/translations'
# additional translation paths
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should remove this one? I'm not sure it's that common to add more paths, so better keep the config simpler? (same below of course)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so too, but there is no consensus about that (others member think otherwise) at least for Twig paths. See previous comments.

@javiereguiluz
Copy link
Member

I still think that we should display paths (for Twig, not translations) ... but this is based on my own experience. If most people think it's better to not display it, let's do that so we can merge this fast. If we receive complaints from users, we can easily change this later.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Pull request passes validation.

@yceruto
Copy link
Member Author

yceruto commented Sep 5, 2018

Removed translations paths only.

paths: ['%kernel.project_dir%/templates']
default_path: '%kernel.project_dir%/templates'
# additional template paths
#paths: []
Copy link
Member

Choose a reason for hiding this comment

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

@javiereguiluz can you hint when this is needed? Still feels like something we could clean :)
Any other opinion from anyone else?

Copy link
Member

Choose a reason for hiding this comment

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

In real apps I've used it 1) to add another directory where templates were defined (yes, I know, this is the obvious purpose!), 2) on symfony.com app I use it to define Twig namespaces, 3) in some personal apps I use it to add public/static/images/ as a directory for templates. Why? Because that way I can use the SVG icons as regular images in SCSS and embed them in Twig templates with {{ source('icons/-------.svg') }}

But again, if most people never change this option, let's remove it from the default config file. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Going back to the simpleness version, anyway it's well documented.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Pull request passes validation.

@ghost ghost merged commit 499af21 into symfony:master Sep 8, 2018
ghost pushed a commit that referenced this pull request Sep 8, 2018
@yceruto yceruto deleted the default_path branch September 9, 2018 01:17
This pull request was closed.
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

Successfully merging this pull request may close these issues.

8 participants