Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created April 25, 2011 12:56
Show Gist options
  • Select an option

  • Save kriswallsmith/940473 to your computer and use it in GitHub Desktop.

Select an option

Save kriswallsmith/940473 to your computer and use it in GitHub Desktop.
Should I map Assetic filters to Twig functions or filters?

Simple function call:

{{ pngout("images/logo.png") }}

Simple filter call:

{{ "images/logo.png"|pngout }}
@kriswallsmith

Copy link
Copy Markdown
Author

I've decided to go with a function because this should be used instead of Symfony2's asset() function.

@dennisjac

Copy link
Copy Markdown

What would the output of pngout() look like? If it's an url then the function should probably be called pngurl().

@marijn

marijn commented Apr 25, 2011

Copy link
Copy Markdown

I'm all in favor of filters, it seems to be a better fit with the actual operation.

@fabpot

fabpot commented Apr 25, 2011

Copy link
Copy Markdown

A filter is better when the value is being filtered/altered (upper cased, encoded, ...). So, the returned value is semantically the same as the input. Here, I think it's a function as the path is just an input value and the output is very different.

@dennisjac

Copy link
Copy Markdown

I agree that a function is more appropriate for the reason Fabien mentioned though I still think that
a) if the function outputs an url it should be renamed to pngurl() to make it more explicit what it is the function actually "out"puts.
b) Are there going to be multiple function for each mime type? What about a function asset_url() that could be used for all types (perhaps with an optional second argument to specify the type explicitly if its not one of the standard types)?

@marijn

marijn commented Apr 25, 2011

Copy link
Copy Markdown

If it's an URL I'm all in favor of making it a function. If it's going to allow image data/uri then I'd like it to be a filter.

I guess if all it does is output a URL than one function for all asset types is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment