* Josh Kamau <[email protected]> [171110 03:47]:
> You can use 'with' to achieve what you want.
> Take a look at this example
>
> https://play.golang.org/p/incDGEmUJK
>
> On Wed, Nov 8, 2017 at 12:03 PM, <[email protected]> wrote:
> > I could not found such token system in golang or any library supporting
> > such format. Can anyone please tell how can I achieve to create such
> > tokens. There should be no dot before the attribue. either it should be
^^^^^^
> > only the attribute like {{Name}} or like {{ test.name }}.
This is not how the template package works. You must use the dot to
signify that the name comes from the data supplied to the Execute method
(e.g. a field, key, or method of the data). An identifier without a
preceding dot is either a keyword used to specify an action (e.g. if,
range, or with), or a function name.
You can use {{.test.name}}, or you can use {{with .test}} and then
{{.name}} as Josh shows above.
It is unclear if you have found the correct documentation, where this is
described. In the documentation at [1], which describes things specific
to html/template, the second paragraph in the Overview directs you to
[2], which describes the text/template package, which is the basis for
the html/template package.
In the text/template documentation, see Actions[3] and Arguments[4] for
more details about what items require a preceding dot.
If you want a much simpler templating system, which only allows simple
substitutions and does not require the dot, it would be a fairly easy
package to write.
...Marvin
[1] https://golang.org/pkg/html/template/
[2] https://golang.org/pkg/text/template/
[3] https://golang.org/pkg/text/template/#hdr-Actions
[4] https://golang.org/pkg/text/template/#hdr-Arguments
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.