Object References
Object references are specific to Haml syntax. They are not supported by Slim or EGO templates.
An object reference is a special object in Go that can provide either id and/or class attributes to an element.
In this example we used the article value as an object reference to the div element. Here is how this might render out:
The article value we used in the example has implemented the following two methods:
Anything that implements func ObjectID() string can be used to provide an id attribute to an element. Likewise, anything that implements func ObjectClass() string can be used to provide a class attribute to an element. A type can implement either method on its own; GoHT only adds the attribute that the value actually supports.
When a value implements both methods, GoHT builds the id from the class and the ID joined with an underscore, class_id, rather than the bare ID alone. That is why the example above renders id="article_article-123" instead of id="article-123": the id includes the article class as a prefix.
If a value implements only ObjectID, the id attribute is the plain, unprefixed value. GoHT still renders an empty class="" attribute in this case, since the object reference syntax always sets up a class attribute even when ObjectClass isn’t implemented.
renders as:
Prefixes
We can also provide a prefix that will be used for the class and id attributes, added in front of the class (if any).
renders as:
The prefix doesn’t have to be a string literal. A Go variable works too: