Is it possible to set quality with Timber's towebp filter? - timber

As the title says. I'm using Timber's built-in filter to convert images to webp, like so:
<img src="{{ image.url|towebp }}">
It looks like the default is 80. Is it possible to change this site-wide, or within the towebp filter, something like this:
<img src="{{ image.url|towebp(100) }}">

Actually you are correct, this piece is correct solution. I made some debug and it passes 100 to quality parameter of the filter.
<img src="{{ image.url|towebp(100) }}">

Related

Twig and Assetic: images names in web directory

To display an image in my Twig template I do
<img src="{{ asset('images/mylogo.png'}}" />
It works fine if I put manually my image 'mylogo.png' in the 'web' directory of my application. But I don't think it is a good way to go. I should use the command 'assets:instal web'
The problem is when I use the command 'assets:instal web' the name of my image is modified (for example the name would be fce32_mylogo_2.png) . . . I think it is assetic who is modifying the name of my image.
But then my Twig template do not find my image when I use to display that image.
Is it normal I put my image 'mylogo.png' manually in my web folder ? I'm not sure about that . . .
Edit: I know I can use this synthax:
{% image 'bundles/myBundle/img/mylogo.png' %}
<img src="{{ asset_url }}" class="img-responsive" alt="">
{% endimage %}
But this does not allow to pass twig variables. I would like to do this:
{% image 'bundles/myBundle/img/'~someVar.logoUrl %}
<img src="{{ asset_url }}" class="img-responsive" alt="">
{% endimage %}
clear your asset dumps and try this:
app/console assets:install web --symlink

How do I generate full URLs for optimised assets using Assetic in Symfony?

I want to include full asset URLs in my page templates, mainly so the Behat failed test page grabs still display properly. I've read this question, which suggests using absolute_url() as of 2.7, however I'm using the {% stylesheets %} or {% image %} tags to filter my assets.
Can anyone advise if there's a better way than doing something like this...
{% image
'#AcemBundle/Resources/public/imgs/logo.jpg'
output='compiled/imgs/logo.jpg' %}
<img src="{{ app.request.getSchemeAndHttpHost() ~ asset_url }}" alt="Logo"/>
{% endimage %}
... ?
Updated
Added full {% image %} tag I'm using.
Use it like this:
<img src="{{ asset('bundles/mybundle/assets/img/logo.png') }}">

Change Sonata Admin Logo based on database record

I have a module for manage images inside my Sonata Admin. I want to display those images where sonata logo is placed, how I can do that? I have the code for get the images in my controller and also the template to display the image but don't know how to use this from Sonata, any advice?
You can override the sonate base template (like you overide any other template) or any block listed inside of it.
there is a block called logo and it looks like this
{% block logo %}
<a href="{{ url('sonata_admin_dashboard') }}" class="brand">
<img src="{{ asset(admin_pool.titlelogo) }}" alt="{{ admin_pool.title }}" />
{{ admin_pool.title }}
</a>
{% endblock %}
In combination with a Twig-Extension it should be no problem to fetch the image out of the database

Absolute path for URL

I have urls such as
http://localhost/test/web/app_dev.php/
http://localhost/test/web/app_dev.php/profile/change-password
http://localhost/test/web/app_dev.php/member/form/test
I would like to get absolute path for these url
I have used often uses absolute path for images or assets such as
{{ asset('bundles/acmedemo/images/title_contact.gif') }}
but those URL are not under some bundle directory.
What way should I use to make absolute path for those URL?
This kind of url can be written using {{ path() }}.
For example:
<a href="{{ path('profile-change-password') }}">
Change password
</a>
http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template
If you need absolute path then ...
{{ url() }}
For example:
<a href="{{ url('my_home_route') }}">
Home
</a>

Passing twig code expression from php

Not sure if that was asked before, probably tho but could not really find any helpful answers.
Somewhere in my code I'm generating some template content with php:
$data = '<img src="{{ asset(\'images/logo.png\') }}" alt="My logo" />';
Then I'm passing it to a twig template:
return $this->render('SWCountryBundle:Country:list.html.twig', array('data' => $data));
And of course within my twig template the result is not what I expect:
{{ data }}
generates the following code in the DOM:
<img src="{{ asset('images/logo.png') }}" alt="My logo" />
Instead I'd like it to interpret the asset location and so display the image correctly.
Any ideas on how I should handle that?
Thanks.
Ok I changed the way to approach things.
Content of $data was fetched from a text file, parsed to add images and stored as a single string.
Since an image needs to be inserted after the text contained by each line of the file, I decided to store those lines in an array instead, pass the array to my Twig template and so I can put the img tag directly in my template.
Every day is a school day!
And btw I don't think there are stupid questions as long as you learn something ;)

Resources