-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
RFC: Allow the Blade view to be set in Markdown page front matter #1517
RFC: Allow the Blade view to be set in Markdown page front matter #1517
Conversation
View data ideasAbstractThinking about some additional ways to pass data to the view (as that becomes the responsibility of the developer as we have no knowledge of the helper). These would be a future addition, but am noting them down now as I'm working with this PR in a real project. Some other static site generators make all front matter properties available in the view. So adding Currently supported: $page->matterThis works out of the box: ---
image: image.png
---
{{ $page->matter('image') }} Props ideaWhat I find meh about the example above in the context of this PR is that you don't get an explicit schema. An improvement could be made so that if the Blade page has For example, the following would require that an image is set in the front matter, but the alt text is optional. @props([
'image',
'alt' => null,
]) With ideaAnother idea is to add a with keyword, where any keys would be added to the view. This is basically just adding all the data directly but with extra steps so I'm not sure if this helps anything. ---
extends: layouts/markdown-page-with-header
with:
image: image.png
lead: Hello World!
--- There is one benefit of this: It makes it clear that the data is intended for the view. If "image" was added to the root properties, it's not obvious if that is intended for HydePHP to use, or if it's a part of the userland template. SlotsIf we implement #1516, an integration between that and this where slots and stacks could be added to the Markdown could be really nice. ---
extends: layouts/markdown-page-with-header
---
# My page
@push('header')
## My header
@endpush
<x-slot name="footer">
## My footer
</x-slot>
## More stuff |
Noting this is easily resolved, but it could change existing sites so might want it for v2. Anyways, a simple array merge does the trick (it's important that the matter is first in the call) // Page compile method
$data = array_merge($this->page->matter->toArray(), [
'title' => $this->page->title,
'content' => $this->page->markdown->toHtml(static::class),
]); |
So we can render front matter properties directly in the Blade. (I don't personally see much point in it, but trying it out for now) See note hydephp/develop#1517 (comment)
This is now implemented in the experimental Bladedown extension. We can try it out there, and consider merging it here later on. https://github.com/hydephp/bladedown |
Summary
This proposal adds a front matter option for Markdown pages to allow a custom Blade template to be used.
Usage
Implementation
Implementation is simple by adding the following method override to the
MarkdownPage
class.This makes the change fully backwards compatible as it null coalesces to the default behaviour.
Alternate implementations
I initially went with
extends
as the front matter key, as that matches the Blade syntax. I also see that Jigsaw uses extends. However Jekyll useslayout
. We could also support both, same as we support both group and category for navigation data.My thoughts on the matter
Something like this was considered when originally creating HydePHP as I did not find it necessary, and it risks adding complexity without value. Additionally, for most sites this is not needed as the various page types have different views that get automatically configured, and an override could make things less obvious.
Furthermore, the general use of HydePHP means that it's okay that most Markdown-based pages look the same in terms of layout. However, I realize now that I think it could be useful for Markdown pages for sites with a lot of Markdown page content to have this option.
And considering how surprisingly light this implementation is codewise it comes down to the following: Is this a design pattern we want to encourage? And if the answer is no, is that reason enough not to implement this? Even if something is discouraged we can still have the option for users do things the way they want. For some people this might fit their workflow. And since it's opt-in and doesn't add any unnecessary boilerplate for those who are happy with the defaults I think this feature could be useful.
I always like to get user feedback, hence why I drafted this as an RFC, paired with a Twitter poll. In addition to knowing if users are for or against this, I would also love to get feedback on the front matter property name issue mentioned above: if we should use
extends
orlayout
.Voting
Please vote with an emoji on this post:
Or vote via the Twitter poll.
Please also leave feedback in the comments!