O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom template functions

We defined our custom template functions in the funcs.go source file found in the shared/templatefuncs folder:

package templatefuncsimport (  "strconv"  "time")func RubyDate(t time.Time) string {  layout := time.RubyDate  return t.Format(layout)}func UnixTime(t time.Time) string {  return strconv.FormatInt(t.Unix(), 10)}

The RubyDate function displays a given time using the time layout specified by the time.RubyDate constant. We call the function in a template using the rubyformat function name.

As noted before, inside the about content template (shared/templates/about_content.tmpl), we use the pipe (|) operator to apply the rubyformat function to the StartTime as shown here:

<p class="rubyStartTime">That's <span class="starttime"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required