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

Add support for named filter arguments #42

Open
tanema opened this issue Dec 2, 2020 · 3 comments
Open

Add support for named filter arguments #42

tanema opened this issue Dec 2, 2020 · 3 comments
Labels
compatibility feature parity Feature parity with Shopify Liquid help wanted

Comments

@tanema
Copy link

tanema commented Dec 2, 2020

System information

  • Version: github.com/osteele/liquid v1.2.4
  • Go: go version go1.13.7 darwin/amd64

Problem

I am receiving syntax errors while trying to parse templates that are meant for shopify. I have filters that look like this

{{image | img_url: '580x', scale: 2}}
{{ order.created_at | date: format: 'date' }}
{{ 'customer.order.title' | t: name: order.name }}

I have tried to just define the filters:

	cfg.AddFilter("t", func(value interface{}) interface{} {
		return value
	})
	cfg.AddFilter("date", func(value interface{}) interface{} {
		return value
	})

And I get a generic Syntax error that does not define what the error is.

Steps to reproduce the behavior

Here is a test that will reproduce this:

package lint

import (
	"testing"

	"github.com/osteele/liquid"
	"github.com/stretchr/testify/assert"
)

func TestPathToProject(t *testing.T) {
	engine := liquid.NewEngine()
	template := `{{ 'customer.order.title' | t: name: order.name }}`
	bindings := map[string]interface{}{}
	engine.RegisterFilter("t", func(value interface{}) interface{} {
		return value
	})
	_, err := engine.ParseAndRenderString(template, bindings)
	assert.Nil(t, err)
}

Possible Solution

I have a hunch that you do not support named arguments to filters.

Follow-up question, it does not seem like your for loop supports else and I cannot seem to override the standard for loop with my own

@osteele osteele changed the title Syntax Error, Possible argument parsing issue Add support for named filter arguments Jun 17, 2021
@osteele
Copy link
Owner

osteele commented Jun 17, 2021

That is correct, this library does not support named arguments to filters. (In fact, I did not know that Shopify did.)

I would be interested in having a fix for this, but I don't promise to find time to write one.

@osteele osteele added compatibility feature parity Feature parity with Shopify Liquid help wanted labels Jun 17, 2021
@osteele
Copy link
Owner

osteele commented Jul 6, 2021

Here is documentation for Shopify's image_url parameters: https://shopify.dev/api/liquid/filters/url-filters#other-image-url-parameters

Here is a test case for filter parameters in the Ruby implementation's parser: https://github.com/Shopify/liquid/blob/9b8e3d437e1ac461fc32bd896e7f35dfa8b94a2a/test/unit/parser_unit_test.rb#L73 (from this bug report against the C implementation — which I just learned exists)

@shopkone
Copy link

shopkone commented Apr 5, 2024

I appear to have come across these issues too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility feature parity Feature parity with Shopify Liquid help wanted
Projects
None yet
Development

No branches or pull requests

3 participants