Skip to content
Gx
GitHub

GX6007: gx.Head in a widget

The view of a widget, or a component that the view uses, has a gx.Head tag.

Cause

The view of a widget, or a component that the view uses, has a gx.Head tag. gx.Head sets the title and the head of a page. A widget is one element on the page of a host. It has no document, so it has no title and no head.

Example

cart/Cart.gx
package cart

props {
  Currency string
}

<gx.Head title="Your cart" />
<section>
  <p>Your cart in {p.Currency}</p>
</section>
cart/route/route.go
package route

import "github.com/alternayte/gx"

type Widget struct {
	gx.Route `GET /widgets/cart`
	Currency string `query:"currency" default:"EUR"`
}
cart/cart.go
package cart

import (
	"github.com/alternayte/gx"
	"app/cart/route"
)

var CartWidget = gx.Widget(func(c *gx.Ctx, in route.Widget) (CartProps, error) {
	return CartProps{Currency: in.Currency}, nil
}, Cart).Tag("acme-cart")

var Routes = gx.Collect(CartWidget)

gx check reports:

gx check
cart/Cart.gx:7:1: GX6007: gx.Head is in the widget acme-cart; a widget has no document, so it has no title and no head

Fix

  1. Remove gx.Head from the component. Show the text as a heading inside the widget.
  2. When a page of the app also uses the component, put gx.Head in the view of the page and not in the component.