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

question about split filter on new line #343

Open
shomodj opened this issue Dec 22, 2023 · 0 comments
Open

question about split filter on new line #343

shomodj opened this issue Dec 22, 2023 · 0 comments

Comments

@shomodj
Copy link

shomodj commented Dec 22, 2023

I'm trying to split a string on new line

package main

import (
	"fmt"
	"github.com/flosch/pongo2"
)

func main() {
	templateString := `
{% for val in my_string|split:'\n' %}
  {{ val }}
{% endfor %}
	`

	template, err := pongo2.FromString(templateString)
	
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	context := pongo2.Context{
		"my_string": "Line 1\nLine 2\nLine 3",
	}

	output, err := template.Execute(context)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println(output)
}
	`

	template, err := pongo2.FromString(templateString)

But I get this error Error: [Error (where: lexer) in <string> | Line 2 Col 31] Unknown escape sequence: \n

Is this possible?
Thanks

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

1 participant