Skip to content

[WIP][2.3][FrameworkBundle][Templating] Generate assets with absolute url #7722

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 5 commits into from
Closed

Conversation

inoryy
Copy link
Contributor

@inoryy inoryy commented Apr 19, 2013

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #5322
License MIT
Doc PR -

This adds support for asset_url helper function, which returns asset absolute url, matching schema, host & port with server one.

Relies on RequestContext class, so if request is made from CLI then router.request_context.* parameters are needed.

I've also added package alias called absolute_url, so a developer can use it inside asset function.
I think it's useful when assets_base_urls parameter is used on production and simple absolute url is needed on dev.
Then a twig variable can be used, defined to be absolute_url on dev or null on prod.

<argument /> <!-- version format -->
</service>

<service id="absolute_url" alias="templating.asset.absolute_url_package" />
Copy link
Member

Choose a reason for hiding this comment

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

A service named absolute_url is a bad idea IMO. It does not descibe at all what the service is about.

thus, making the alias target the abstract service looks weird to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea was to add a simple name that developers can reference when calling asset().
Do you think I should get rid of the alias completely or change to something else?

Copy link
Member

Choose a reason for hiding this comment

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

What you pass as argument when calling asset() is not a service id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, misunderstood the setup. Thanks!

@fabpot
Copy link
Member

fabpot commented Dec 31, 2013

What about doing something simpler: adding a third option to the asset function for absolute URLs (which would basically do {{ app.request.getBaseUri ~ asset(...) }}) -- that's a viable option now that Twig support named arguments: asset('foo.png', absolute=true).

@qpautrat
Copy link

Hello everyone,

Any updates on this subject? @fabpot
I think it's really usefull.

Thanks.

@fabpot
Copy link
Member

fabpot commented Mar 14, 2014

Closing in favor of #10451

@fabpot fabpot closed this Mar 14, 2014
fabpot added a commit that referenced this pull request Mar 15, 2014
…ts urls (romainneutron)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[TwigBundle] Add possibility to generate absolute assets urls

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT
| Doc PR        | symfony/symfony-docs#3683

This is another approach of #7722

 - [x] Add unit tests
 - [x] Update doc

Commits
-------

76b8851 [TwigBundle] Add possibility to generate absolute assets urls
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.

6 participants