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

use in in if result not as exepected #276

Open
jiangbo0216 opened this issue Oct 12, 2021 · 0 comments
Open

use in in if result not as exepected #276

jiangbo0216 opened this issue Oct 12, 2021 · 0 comments

Comments

@jiangbo0216
Copy link

	tpl, err := pongo2.FromString(`{% for el in ssrCatalogList %} {% if "number" in (el.OlType) %} {{forloop.Counter}} {% endif %} {%endfor%}`)
	if err != nil {
		panic(err)
	}
	if err != nil {
		panic(err)
	}

	// Now you can render the template with the given
	// pongo2.Context how often you want to.
	out, err := tpl.Execute(pongo2.Context{"ssrCatalogList": []interface{}{
		map[string]string{"IsTitle": "number1234567890", "Text": "fdfd", "OlType": "dsdsnumberdsds"},
		map[string]string{"IsTitle": "number1234567890", "Text": "ffff"},
	}})
	if err != nil {
		panic(err)
	}
	fmt.Println(out) // Output: Hello Florian!
	tpl, err := pongo2.FromString(`{% for el in ssrCatalogList %} {% if "number" in (el.OlType or "") %} {{forloop.Counter}} {% endif %} {%endfor%}`)
	if err != nil {
		panic(err)
	}
	if err != nil {
		panic(err)
	}

	// Now you can render the template with the given
	// pongo2.Context how often you want to.
	out, err := tpl.Execute(pongo2.Context{"ssrCatalogList": []interface{}{
		map[string]string{"IsTitle": "number1234567890", "Text": "fdfd", "OlType": "dsdsnumberdsds"},
		map[string]string{"IsTitle": "number1234567890", "Text": "ffff"},
	}})
	if err != nil {
		panic(err)
	}
	fmt.Println(out) // Output: Hello Florian!

the only diff is "number" in (el.OlType or "") and "number" in el.OlType, the result is different

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

No branches or pull requests

2 participants