Anyway, I was trying to get a simple webapp going last night and I want to separate the HTML code from the webapp code, so I wanted to use the template module. I was working on the guestbook example and I wanted to add a sign out URL. So the previous code looked something like this:
So how do you add a template variable for my sign out URL? The template data goes into Execute() in the 2nd parameter, so I can't just add a 3rd parameter. The 2nd parameter is already a neatly-packaged array from the datastore, so I can't affect that. So then I figure I need to create another data structure to include both the array and my URL string. This is when I stumble against the syntax as well as trying to find examples out there. I end up trying something like this:
That results in this error message:
line 19: name not exported: theGreetings in type *hello.RootTemplateParamsAll of these problems were fixed by changing the field names in the struct to capitalized (along with getting some more sleep ;)). (I saw this note in the template documentation: If Field is a struct field or method name, it must be an exported (capitalized) name.) I'm not a fan of when a language dictates your coding style. I'm also not a fan of camelCase, but I also wasn't a fan of 2-space indention for Drupal coding styles, either, and I've gotten over that.
So anyway, all this to say that I'm finding Go difficult to pick up, much like any new language, I suppose. I already have an idea of a site I'd like to do, but these difficulties make me think I'm putting the cart before the horse, so to speak.
Post a Comment