diet-ng icon indicating copy to clipboard operation
diet-ng copied to clipboard

[wishlist] Allow mixin / D declarations in `extends` templates

Open quickfur opened this issue 8 years ago • 0 comments

Currently, if a Diet template begins with extends, the only thing allowed in the remainder of the template is block declarations. I don't know how hard / likely it is to implement this, but it would be very nice if certain non-block declarations were permitted, such as D functions or Diet mixins, e.g.:

//- standardpage.dt
html
    head
        title
            block title
    body
        block body

//- accountcreation.dt
extends standardpage
mixin standardbutton(label, url)
    form(method="POST", action=#{url})
        button #{label}

block title
    |Account creation

block body
    h1 Account creation
    form(action=#{url})
        block formBody
    nav
        block navBody

//- newaccount.dt
extends accountcreation
block formBody
    +standardbutton('New account', "/accounts/new")
    +standardbutton('Upgrade old account", "/accounts/upgrade")

The point is that I'd like to declare standardbutton only for templates that extend accountcreation. Currently, this isn't allowed, so I have to move the declaration up to the top-level standardpage template. This pollutes the top-level template with declarations that are only used in a subset of derived templates.

Similarly, it would be nice to allow the same thing for D function declarations as well, so that I can make D functions available to certain subhierarchies of inherited templates.

quickfur avatar Dec 06 '17 01:12 quickfur