On Aug 13, 6:08 pm, si guy wrote:
> Block would also hide complexity of your view logic... When why not just have a man-in-the-middle set of functions to handle this, rather than complicating the template system?
> I like to use a map of templates initialized at boot using parseglob etc. to setup all of the template nesting, why does it need to be more complex?
Blocks makes templates more self-contained and simpler to write and
understand. We remove some cognitive load -- the "which/how templates
are assembled in this project?" part of understanding a template set.
And besides, this is the template engine job.
You're seeing a lot of complexity but it is a rather simple concept,
really. And in terms of implementation, my current version adds about
200 lines to text/template.
> Would there be runtime tradeoffs?
No, it is really really absurdly cheap to parse and execute. It is
like an {{if}}.
> Sorry to be pessimistic but this sounds like it will move a lot of view logic out of go code and into template code, which is harder to understand and debug, especially when it is mingled amongst HTML.
I believe it is the opposite. You can parse a larger set of templates
and because they are self-contained, just need to read templates to
know what is going on, independently of the strategy used to load and
assemble them. That said, text/template needs some better debugging
messages.
> I wrote php for a while doing mvc pattern apps, and keeping view logic out of the templates proved massively beneficial.
But blocks are not view logic. They are template logic (as in template
from MVT). It's just some basic assembling done by the template
author.
-- rodrigo