To clarify, I am thinking along the lines of a ParseFiles that only requires the base template to be listed. So in creating the template, I would do something like this:
t, err := template.ParseBaseFile("base.html")
And base.html would look something like this:
<!DOCTYPE html>
<html>
<head></head>
<body>Child is {{ template "/child.html" . }</body>
</html>
So it's clear hear that an additional template needs to be parsed to render the base template. If we just take "/child.html" as a name, then we need to have this defined somewhere. What I am suggesting instead is that when we run across something with a leading slash (or some other means of denoting this as a file path instead of a name), we treat this as a file path that is relative to a root template path directory specified previously, in which case we have all the information we need there in the template to locate the file and attempt to parse it. In this manner, we could parse all embedded templates in the process of parsing their containing templates. This cannot be done if "/child.html" is treated strictly as a name, of course. As a file path, however, it is self-defining.
So if we were able to specify file paths instead of just names within templates, not only would this be more explicit -- I know exactly where to look for the template that will be included here, rather than having to go back and match the name to wherever its content is stored -- but this would eliminate the possibility of conflicts created by files having different paths but the same base name as might happen when using ParseFiles and it would be good deal more straightforward and in turn maintainable. My opinion.
As a bonus, if there were a way of setting a path list for templates pointing to embedded file templates, then packages could add to or modify this list, so that default templates could easily be provided and overridden as desired, since each path could be checked in turn for the specified file, first one found wins.
Does that help to understand what I'm getting at?
On Tuesday, August 12, 2014 9:28:23 AM UTC-4, Matt Silverlock wrote: