template icon indicating copy to clipboard operation
template copied to clipboard

Pug template is not working with Pug official examples

Open keshon opened this issue 4 years ago • 2 comments

I'm struggled with PUG template using official PUG example like this one:

- var user = {description: 'foo bar baz'}
- var authorised = false
#user
  if user.description
    h2.green Description
    p.description= user.description
  else if authorised
    h2.blue Description
    p.description.
      User has no description,
      why not add one...
  else
    h2.red Description
    p.description User has no description

I'm getting this error:

template:5: template:9: Error lex: lexClass: expect class name line: 9

Also comparison with == operator:

if .someVar== "someValue"
    div someVar has someValue

leads to:

template: index:131: unexpected "=" in operand

keshon avatar Mar 27 '21 07:03 keshon

I feel a lot of confusion here especially with '.' prefix before variable in Basic example. Maybe this is the issue but what is right example of making simple comparison in fiber Pug template? I tried every combination with no expected results

keshon avatar Mar 27 '21 07:03 keshon

The pug engine is just translate pug syntax to golang template syntax, so you could use eq directive to accomplish your string comparision.

if eq .someVar "someValue"
    div someVar has someValue

laeo avatar Mar 02 '22 13:03 laeo