Isomorphic Templates

In the previous chapter, we provided an introduction to GopherJS, and we covered code examples to perform various front-end operations. One of the interesting tasks that we performed on the client side, was template rendering, using an inline Go template. However, rendering inline Go templates in the web browser is not a maintainable solution. For one thing, mixing HTML code from an inline Go template, along with Go source code, can become an unmaintainable arrangement as the project codebase grows. In addition to this, real-world web applications often require having multiple template files that are often nested together with a layout hierarchy in mind. In addition to that, the template package from Go's standard library was designed particularly for templates rendered on the server side since it depends on accessing template files from the filesystem.

To fully unleash the power of templates across environments, we need a solution that provides more flexibility to render any template within a set of templates for a given project. This flexibility can be found by implementing isomorphic template rendering using the isokit package from the Isomorphic Go toolkit. Using the functionality from the isokit package, we can render a template belonging to a template set, either on the server side or on the client side, and we'll show you exactly how that's done in this chapter.

Specifically, we will cover the following topics in this chapter:

  • The web template system
  • IGWEB page structure
  • Template categories
  • Custom template functions
  • Feeding data to the content template
  • Isomorphic template rendering
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.165.62