Core: "View" doesn't print data which is 0 (integer)

Created on 27 Aug 2018  路  5Comments  路  Source: adonisjs/core

Package version

  "version": "4.1.0",
  "adonis-version": "4.1.0",
    "@adonisjs/ace": "^5.0.2",
    "@adonisjs/antl": "^2.0.6",
    "@adonisjs/auth": "^3.0.5",
    "@adonisjs/bodyparser": "^2.0.3",
    "@adonisjs/cors": "^1.0.6",
    "@adonisjs/fold": "^4.0.8",
    "@adonisjs/framework": "^5.0.7",
    "@adonisjs/ignitor": "^2.0.6",
    "@adonisjs/lucid": "^5.0.4",
    "@adonisjs/mail": "^3.0.8",
    "@adonisjs/session": "^1.0.25",
    "@adonisjs/shield": "^1.0.6",
    "@adonisjs/validator": "^5.0.3",

Node.js and npm version

node.js: v10.8.0
npm: 6.4.0

Sample Code (to reproduce the issue)

controller:

return view.render('pages.confirmation',{status:0})

or

return view.render('pages.confirmation',{status:1})

view:

{{status}}
@if(status===1)
  do sth
@elseif(status===0)
  do sth
@endif

The view evaluates the value as empty string / null / undefined and prints nothing to screen when status is 0 . If i set status to other than 0, it prints the number to screen properly. Is this a bug? If it is not, it should also print 0 (integer).. I am not sure the problem is about the data sending mechanism or printing data to screen mechanism.
Thank you for your helps.

Critical Alpha Bug

Most helpful comment

Yes, seems like a bug. As a workaround, you can say.

view.render('pages.confirmation',{status: String(0)})

and use it follows inside the view

@elseif(status === '0')

All 5 comments

Yes, seems like a bug. As a workaround, you can say.

view.render('pages.confirmation',{status: String(0)})

and use it follows inside the view

@elseif(status === '0')

Okey, thank you for confirmation. There are lots of workaround to resolve this issue. No problem for me but I just want to inform you. 馃憤

Late to the game, but have seen this is still open.
I don't think this is actually a bug on AdonisJS side, as after briefly looking at the code,
view.render(...) is just a proxy for the same function on the Edge template engine.

I am almost done with the newer version of Edge https://github.com/edge-js/edge/tree/develop. Just need some time to work on the docs and get it out

Fixed and released in the new version of edge and is compatible with v5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amrayoub picture amrayoub  路  4Comments

begueradj picture begueradj  路  3Comments

devcaststudio picture devcaststudio  路  3Comments

krunaldodiya picture krunaldodiya  路  3Comments

seanc picture seanc  路  4Comments