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

default filter doesn't seem to work on dictionary elements #161

Closed
NocturnalSolutions opened this issue Dec 22, 2017 · 0 comments
Closed
Labels

Comments

@NocturnalSolutions
Copy link

NocturnalSolutions commented Dec 22, 2017

import Stencil

let aNilString: String? = nil

var testContext: [String: Any] = [
    "notNil": "I'm Not Nil" as Any,
    "nil": aNilString as Any
]

testContext["subDictionary"] = testContext

let templateString = """
{{ notNil|default:"It's Nil" }}
{{ nil|default:"It's Nil" }}
{{ subDictionary.notNil|default:"It's Nil" }}
{{ subDictionary.nil|default:"It's Nil" }}
"""

let template = Template(templateString: templateString)
let result = try template.render(testContext)
print(result)

Expected result:

I'm Not Nil
It's Nil
I'm Not Nil
It's Nil

Actual result:

I'm Not Nil
It's Nil
I'm Not Nil

Here's a full project you can clone and run to see this happening in real time. This is a distillation of behavior I'm seeing happening on a "real" project (a Kitura site).

Other filters such as uppercase seem to work fine on dictionary elements, though I haven't tested all of them.

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

No branches or pull requests

2 participants