New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement template inheritance via {{% BLOCKS }}
pragma.
#130
Conversation
See also mustache/spec#38 for an ongoing discussion (with several recommendations which resemble this one). |
Awesome.. Can't wait. Is this planned for 2.2 or 2.3 ? |
Probably 2.2. |
It seems that this feature has been implemented in the current version (2.3) of mustache.php, but I can't find the documentation for it. |
It doesn't look like |
@rafi is right. This feature has not been merged yet. Feel free to use the feature branch in the interim though. |
oops sorry, didn't notice there is a branch per feature. |
@nicolas-t It hasn't been merged because there's not really a consensus on how template inheritance should work in Mustache yet. See mustache/spec#38 for discussion. Specifically:
|
Any news on this awesome feature? |
I just rebased the feature branch onto |
@calmdev I got a notification (and see a comment on your profile) but nothing shows up here. I take it you got it working? |
@bobthecow actually no, I was not able to get it working. I tried with the latest I downloaded a copy of the master back in January for a project I was working on before this PR was opened and remember manually merging the changes into the master that I was working with when I saw this PR. For some reason that copy works perfectly fine, but is obviously well behind now. I'd really love it if you could verify that the examples posted here are working for you with the lastest I'm itchin' to get us moved over to Mustache.php The issue I was running into seemed specifically related to the parser throwing an exception when |
Hey Guys, We have a JAR to do the same thing, and I wanted to implement the PHP version, being a LAMP guy. |
Yeah, so I think there is a difference between JAVA and PHP versions. So how does the open source community stay on the same page? |
@WinWinHost they're different because there's no consensus on how it should work between the different implementations, and it's not in the spec. There are almost as many ways to implement template inheritance as there are mustache libraries with template inheritance. Unless and until it actually gets standardized, there will be differences. |
What do you think the LOE would be on rewriting that functionality over into the PHP version? |
What's keeping this branch out of master? |
@rafi This hasn't been released because there's no consensus on template inheritance between the different mustache implementations (see my comment above) |
Hey @bobthecow, @jazzdan and I were having trouble getting this branch to work. We created this test, which fails with Next we found that |
@dtb Unfortunately this branch is effectively abandoned at this point. It hasn't kept up with development of the main library, and probably needs to be reimplemented on a fork from the current dev branch. See above for why I haven't taken that on yet :) |
This will be deprecated by #198 when it's merged, so I'm preemptively closing this pull request. |
This is a proof-of-concept implementation of template inheritance via blocks.
Say we have a template named
layout.mustache
. This would be our generic site layout template, consisting of all the sorts of things you'd expect in a layout template. In addition, it would have a number of blocks defined. The blocks look like Mustache sections, but they're denoted with{{$ block }}
tags instead of#
.The blocks defined here are
{{$ title }}
,{{$ stylesheets }}
,{{$ header }}
,{{$ content }}
and{{$ scripts }}
.By default, blocks merely delineate sections of the template which can be extended (replaced) in subtemplates. If the parent template itself is rendered, the block tags are simply rendered as if they are truthy sections.
This
layout
template can then be extended by other sub-templates, which declare their intention by adding aparent=layout
to the{{% BLOCKS }}
pragma tag:Upon rendering this
page.mustache
, the subtemplate blocks will be substituted for the parent blocks, resulting in (approximately) this:In our example, we didn't override every block: the
{{$ scripts }}
block retained its default value. We could also create a new subtemplate which extendspage.mustache
, saycustom-page.mustache
. That subtemplate might only replace the{{$ content }}
block ofpage.mustache
, and inherit the rest.Note that
page.mustache
could even define new blocks. Maybe add a{{$ main }}
and{{$ complimentary }}
section inside{{$ content }}
:Then sub-subtemplates could choose to override just the
{{$ main }}
block, while leaving{{$ content }}
and{{$ complimentary }}
intact.