yosssi/gold

Optional blocks

ahall opened this issue · 4 comments

When I have a layout I'd like to have something like:

block title
title Blah

Which means I could override title in my templates if I wanted to, otherwise it would use title blah.

At the moment this is not possible and you're forced to specify the blocks in the derived templates. I think this would be a good feature and template engines like jinja2 allow you to do this.

@ahall Thanks for your comment! I will consider how to implement this function. Just a moment, please!

@ahall I just implemented this function on the optional-blocks branch on the PR #5. Could you check this function? If it would be OK, I would merge PR #5 to the master branch.

You can set a default value to the blocks as below:

parent.gold

doctype html
html
  head
    block title
      title Default Title

child1.gold

extends ./parent

block title
  title Child1 Title

child2.gold

extends ./parent

child1.gold template generates the following HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Child1 Title</title>
    </head>
</html>

child2.gold template generates the following HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Default Title</title>
    </head>
</html>

This is awesome. Tested it and it works nicely. Thanks for this. This makes things much more useful for me.

@ahall Thank you very much for your reviewing! I merged this function to the master branch.