Skip to content
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

Filter doesn't work #32

Open
zimt28 opened this issue Jun 14, 2017 · 2 comments
Open

Filter doesn't work #32

zimt28 opened this issue Jun 14, 2017 · 2 comments

Comments

@zimt28
Copy link

zimt28 commented Jun 14, 2017

One of my filters doesn't work, and I can't figure out why. Every other filter seems to work, but the date filter in the following example doesn't work, even if I change its name to something else.

defmodule Test.LiquidFilters do
  def date(date) do
    Timex.format!(date, "%d.%m.%Y", :strftime)
  end

  def add_ten(value) do
    value + 10
  end
end

defmodule Test do
  def run do
    Liquid.Filters.add_filters(Test.LiquidFilters)
    
    data =
      %{
        "my_date" => Ecto.DateTime.utc(),
        "my_int" => 32
      }
    
    template = 
      """
        {{ my_date | date }} <br />
        {{ my_int | add_ten }}
      """

    {:ok, output, _} =
      template
      |> Liquid.Template.parse
      |> Liquid.Template.render(data)

    output
  end
end
iex(1)> Test.run()
"  2017-06-14 18:00:00 <br />\n  42\n"
iex(2)> Ecto.DateTime.utc() |> Timex.format!("%d.%m.%Y", :strftime)
"14.06.2017"
@art4ride
Copy link
Collaborator

art4ride commented Jun 16, 2017

Hey, @zimt28!

date is reserved for the default filter which formats date ("%F %T" by default)

So when you add a custom filter it will not override the default liquid filter.

Simply renaming your filter to custom_date solves your problem (don't forget to rename it in the template too ;) ).

Another option is to use a default date filter and pass a "%d.%m.%Y" as an argument like:
{{ my_date | date: "%d.%m.%Y" }}

I hope this will help,
Vladi

@nulian
Copy link
Collaborator

nulian commented Sep 5, 2017

This will probably will be added overwriting existing filters because we ourselves also use overwritten filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants