Skip to content

question about split filter on new line #343

@shomodj

Description

@shomodj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions