Skip to content

Add support for named filter arguments #42

@tanema

Description

@tanema

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions