user1775718
user1775718

Reputation: 1578

SWIG variable persistance

I've got an app which is constructed using the SWIG templating engine with express. When I send my response for rendering I send back variables which are occasionally null. I've used swig to log out those variables on the page and it seems that if they are null then the last known non-null value is used.

eg. I start off with all the birds (the app is about birds) showing and the type and subtype is set to null. If I browse to 'golden eagle' then the node app sends they type and subtype in the response object that swig uses to render; so hence type will be 'birds of prey' and subtype will be 'eagle'. When I click my breadcrumb link to go back to 'all birds' the console shows that I send the right info (type and subtype are set as null) but on the page itself SWIG logs them out as still being 'birds of prey' and 'eagle'.

In swig.init I've even set the cache to false but it doesn't seem to matter.

Anybody know anything about this?

Thanks

James

Upvotes: 3

Views: 1545

Answers (1)

menzoic
menzoic

Reputation: 864

Use the 'set' tag

"Set a variable for re-use in the current context."

{% set foo = "anything!" %}
{{ foo }}
// => anything!

http://paularmstrong.github.io/swig/docs/tags/#set

Upvotes: 2

Related Questions