Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add instructions on how to use the official Twig extensions repo#7616

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@mpdude
Copy link
Contributor

There are several references to the official Twig extensions repository, but we don't mention how easy it actually is to use that.

When#7613 is merged we also should update the notes added there to include a reference to this new section.

from having a look at the `Twig Bridge`_ which contains most of
the extensions provided by the Symfony Framework.

We also have:doc:`a short article</reference/using_twig_extension_repository>`
Copy link
Member

Choose a reason for hiding this comment

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

/templating/using_twig_extension_repository

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 also rename the new file to something shorter like/templating/twig_extension_repository

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed

@mpdudempdudeforce-pushed thecookbook_twig_extensions branch fromaabaced to120e9beCompareMarch 13, 2017 12:43
# app/config/services.yml
services:
twig_extension.intl:
twig_extensions.intl:
Copy link
Contributor

Choose a reason for hiding this comment

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

The namespace should not have an "s" IMHO, what do others think?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I chose that because the repo is called "Twig Extensions". Thus I'd call a corresponding bundle "TwigExtensionsBundle", which would give this name.

Or should we better recommend prefixing it withapp?

Copy link
Member

Choose a reason for hiding this comment

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

I guessapp. is better since there may be other bundles who try the same that we do here.

mpdude reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Now that you mention it... For example, I've come acrossthis one.

Would you guys recommend using a 3rd party bundle instead of providing instructions?

Note I am not affiliated with that bundle in any way and cannot endorse it.

Copy link
Member

Choose a reason for hiding this comment

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

I would always strive to keep the number of external dependencies as low as possible. Given that registering services is not hard and does not require much work I would only require that bundle if you need one of the extensions shipped with it.

mpdude reacted with thumbs up emoji
from having a look at the `Twig Bridge`_ which contains most of
the extensions provided by the Symfony Framework.

..tip::
Copy link
Member

Choose a reason for hiding this comment

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

we could use.. seealso:: instead here

`Twig official extension repository`_.
When writing your own extensions, you might want to learn
from having a look at the `Twig Bridge`_ which contains most of
the extensions provided by the Symfony Framework.
Copy link
Member

Choose a reason for hiding this comment

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

framework


..tip::

We also have:doc:`a short article</templating/twig_extension_repository>`
Copy link
Member

@xabbuhxabbuhMar 14, 2017
edited
Loading

Choose a reason for hiding this comment

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

We always avoid the first person perspective in the docs. This could be rewritten to something like "Read ... on how to use [...]".

How to Use the Twig Extensions Repository
=========================================

The `Twig official extension repository`_ contains (as of writing) some
Copy link
Member

Choose a reason for hiding this comment

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

The official Twig extensions repository [...]

Copy link
Member

Choose a reason for hiding this comment

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

I think we can drop the "as of writing" part

`documentation`_.

This repository is meant as an extension to Twig in general. So, it
is does *not* provide a direct means to register itself with the
Copy link
Member

Choose a reason for hiding this comment

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

So, itis does not [...]


This repository is meant as an extension to Twig in general. So, it
is does *not* provide a direct means to register itself with the
Symfony Framework (it is not a Bundle).
Copy link
Member

Choose a reason for hiding this comment

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

framework

Copy link
Member

Choose a reason for hiding this comment

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

bundle

is does *not* provide a direct means to register itself with the
Symfony Framework (it is not a Bundle).

It is, however, very easy to get the extensions set-up in Symfony.
Copy link
Member

Choose a reason for hiding this comment

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

set up

the right class name.

First, add the Twig Extensions repository as a dependency in your
project. Assuming you are using Composer, run
Copy link
Member

@xabbuhxabbuhMar 14, 2017
edited
Loading

Choose a reason for hiding this comment

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

IMO we should ignore that in theory there are other ways to install the extensions and reword this to "First, install the Twig extensions using Composer".

..code-block::php
// app/config/services.php
use \Twig_Extensions_Extension_Intl;
Copy link
Member

Choose a reason for hiding this comment

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

In Symfony, we usually don't haveuse statements for classes from the global namespace.

And that's it! For example, you should now be able to use the
``localizeddate`` filter to format a date according to the request's
current locale:
Copy link
Member

Choose a reason for hiding this comment

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

[...] to the current request's locale

find all the extra Twig functions, filters, tags and tests that are
already added by the Symfony Framework.

We also have documentation on:doc:`how to write your own Twig extension</templating/twig_extension>`.
Copy link
Member

Choose a reason for hiding this comment

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

first person :)

app.twig_extensions.intl:
class:Twig_Extensions_Extension_Intl
tags:
-{ name: twig.extension }
Copy link
Member

Choose a reason for hiding this comment

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

maybe also mark the service as private

@mpdude
Copy link
ContributorAuthor

@xabbuh Thanks for the thorough review, all fixed!

@mpdude
Copy link
ContributorAuthor

@HeahDude /@xabbuh any other wishes/remarks?

How to Use the Twig Extensions Repository
=========================================

The `Twig official extensions repository`_ contains some
Copy link
Member

Choose a reason for hiding this comment

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

Twig official extensions repository (or change the target at the end of the document)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed link below

@xabbuh
Copy link
Member

👍 the build is passing now :)

Status: Reviewed

..index::
single: Using the Twig Extensions Repository

How to Use the Twig Extensions Repository

Choose a reason for hiding this comment

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

Can we change the title of this article? TheRepository word is confusing here. What we want is to enable/use the official Twig extensions in Symfony apps.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Unfortunately, "The official Twig extensions" isn't very helpful either, rather misleading...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

"Using Twig extensions not provided as a bundle"...? Meh.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about repeating what's below and just add "official":

How to Use the Twig Official Extensions

@@ -0,0 +1,93 @@
..index::
single: Using the Twig Extensions Repository

Choose a reason for hiding this comment

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

I wonder if we really need this article. We don't explain those extensions (because they are documented in their own repo) and they are not special regarding the Symfony+Twig config: they are enabled just like any other Twig extensions.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You're right in that there is nothing special with these extensions.

However, all Twig Extensions I normally use are either part of a bundle or there is a bundle to set them up in Symfony.

I felt there was kind of a gap for the "official" Twig Extensions. They're mentioned in the Symfony docs, but every time I need them it takes me moment to remind myself that I have to set them up that way - which is why I wrote this article to help the future me :-).

@mpdude
Copy link
ContributorAuthor

So guys, please decide if you'd merge this or not... If you want to, then I will have a look at the conflicts.

@robfrawley
Copy link
Contributor

👍 for adding this documentation of the "Official Twig Extension" usage.

Jibbarth reacted with thumbs up emoji

@weaverryan
Copy link
Member

Sorry for the delay on this@mpdude - it's a good PR as usual from you. Because things have changed (I'm talking about the introduction to Flex), my vote would be tonot merge this. Well, actually, Ido think we should mention (somewhere) that this libraryexists with details on how to install it. But in Flex, it's as simple as runningcomposer require and then un-commenting the extension you want.

So, should we merge this PR to older branches, or just update it with the simpler instructions and merge to master?

@mpdude
Copy link
ContributorAuthor

Let's look ahead and not merge into old branches.

However, I haven't yet worked with Flex myself, so I am unsure if I can be of any help here?

@weaverryan
Copy link
Member

@mpdude I tend to agree :). When you install the twig extensions repo in flex, you're given this file:https://github.com/symfony/recipes/blob/master/twig/extensions/1.0/config/packages/twig_extensions.yaml. So basically, the user only needs to go to this file and uncomment the extensions they want :). I think updating this PR (and just removing the stuff that's not needed anymore) is the easiest way forward.

@javiereguiluz
Copy link
Member

To move things forward, I propose to close this in favor of#9035. Thanks!

@mpdudempdude deleted the cookbook_twig_extensions branchJanuary 11, 2018 17:31
javiereguiluz added a commit that referenced this pull requestJan 12, 2018
This PR was merged into the 4.0 branch.Discussion----------Mention the official Twig extensionsThis finishes#7616 in a more concise way now that we can assume that the app is using Flex.Commits-------0084f14 Mention the official Twig extensions
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@xabbuhxabbuhxabbuh left review comments

+2 more reviewers

@HeahDudeHeahDudeHeahDude left review comments

@roman-1983roman-1983roman-1983 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.0

Development

Successfully merging this pull request may close these issues.

8 participants

@mpdude@xabbuh@robfrawley@weaverryan@javiereguiluz@roman-1983@HeahDude@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp