Home > Article > Backend Development > Why Isn\'t My `if` Check Working in Go Templates?
Go Simple If Check Not Working in Template
This question addresses an issue faced when trying to perform an if check on a bool field within a struct using Go templates. Despite several attempts, the template was not rendering correctly.
The provided Category struct includes a boolean field isOrientRight. When attempting to check if this field is true using if statements, the template would stop rendering.
Solution
The solution lies in exporting the field you want to access in the template. Go requires all fields that need to be accessed from templates to be exported, meaning their first letter must be capitalized.
<code class="go">type Category struct { ImageURL string</code>
The above is the detailed content of Why Isn\'t My `if` Check Working in Go Templates?. For more information, please follow other related articles on the PHP Chinese website!