Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:40:59+00:00 2026-06-07T21:40:59+00:00

How do I get nested templates like Jinja has in the python runtime. TBC

  • 0

How do I get nested templates like Jinja has in the python runtime. TBC what I mean is how do I have a bunch of templates inherit from a base templates, just filing in blocks of the base templates, like Jinja/django-templates does. Is it possible using just html/template in the standard library.

If that is not a possibility, what are my alternatives. Mustache seems to be an option but would I then be missing out on those nice subtle features of html/template like the context sensitive escaping etc.? What other alternatives are ther?

(Environment: Google App Engin, Go runtime v1, Dev – Mac OSx lion)

Thanks for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:41:02+00:00Added an answer on June 7, 2026 at 9:41 pm

    Yes it is possible. A html.Template is actually a set of template files. If you execute a defined block in this set, it has access to all the other blocks defined in this set.

    If you create a map of such template sets on your own, you have basically the same flexibility that Jinja / Django offers. The only difference is that the html/template package has no direct access to the file system, so you have to parse and compose the templates on your own.

    Consider the following example with two different pages (“index.html” and “other.html”) that both inherit from “base.html”:

    // Content of base.html:
    {{define "base"}}<html>
      <head>{{template "head" .}}</head>
      <body>{{template "body" .}}</body>
    </html>{{end}}
    
    // Content of index.html:
    {{define "head"}}<title>index</title>{{end}}
    {{define "body"}}index{{end}}
    
    // Content of other.html:
    {{define "head"}}<title>other</title>{{end}}
    {{define "body"}}other{{end}}
    

    And the following map of template sets:

    tmpl := make(map[string]*template.Template)
    tmpl["index.html"] = template.Must(template.ParseFiles("index.html", "base.html"))
    tmpl["other.html"] = template.Must(template.ParseFiles("other.html", "base.html"))
    

    You can now render your “index.html” page by calling

    tmpl["index.html"].Execute("base", data)
    

    and you can render your “other.html” page by calling

    tmpl["other.html"].Execute("base", data)
    

    With some tricks (e.g. a consistent naming convention of your template files), it’s even possible to generate the tmpl map automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get some nested params. I have an Order that has
I used to be able to do something like this to get a nested
I am attempting to get rails routes paths via nested resources. I have looked
I'm trying to get SQL Server to order by a column from a nested
In Rails 3 edge, I have set up two nested resources like this: config/routes.rb
I have a filesystem like XML structure, and now I want to get the
Let's say I have a nested resource like in the Rails guide example: http://guides.rubyonrails.org/routing.html#nested-resources
I am trying to do is to loop this HTML and get a nested
I've rebuilt my network map and now I can't seem to get my nested
In a nested WPF ToolBarPanel-ToolBar-Menu we want to get rid of the grip handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.