Skip to content
Gx
GitHub

GX2008: fragment free variable

A fragment uses a variable that is not one of its parameters.

Cause

A fragment uses a variable that is not one of its parameters. The generated fragment function can use its parameters and p only.

Example

cart/Cart.gx
package cart

props {
  Total int
}

<div>
  total := p.Total
  tax := total / 10
  <span #total(total int)>{total + tax}</span>
</div>

gx check reports:

gx check
cart/Cart.gx:10:36: GX2008: undefined: tax

Fix

  1. Add the variable to the parameter list of the fragment.
  2. Or calculate the value in the fragment from its parameters.