Return null when original file doesn't exist #121

Closed
wants to merge 1 commit into from

2 participants

@ChubV

It is hard to manage images that are optional.
So is not it better to return null when original file doesn't exist.
It allows us to write something like {{ entity.getImage | apply_filter('some') | default('placeholder.img') }}.

@ChubV ChubV Return null when original file doesn't exist
It is hard to manage images that are optional.
So is not it better to return null when original file doesn't exist.
It allows us to write something like `{{ entity.getImage | apply_filter('some') | default('placeholder.img') }}`.
6efc87b
@avalanche123

why not do something like:

{{ entity.getImage | default('placeholder.img') | apply_filter('some') }}
@ChubV

Yeah. That is the solution. But there are more pros of returning null:
Scenario N1: {{ entity.getImage | default('http://placekitten.com/115/111') | apply_filter('some') }}
Scenario N2: <img src="{{ entity.getImage | apply_filter('some') }}" /> triggers browser to make an unnecessary request when getImage() returns null (so apply_filter returns something like /media/cache/some).
In case when apply_filter would return null - no additional request done.

And also it is not good idea to return cache folder path, when something wrong...

@avalanche123

agreed, template helpers should short-circuit null values, can you modify Twig extension and PHP helper to return null if path is null? I don't want to add another stat call to cache path resolver.

@ChubV

Ok, i think it will be a solution.

@ChubV

Ok, there is another PR #122

@ChubV ChubV closed this Feb 19, 2013
@ChubV ChubV deleted the ChubV:patch-1 branch Feb 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment