admin管理员组

文章数量:1289565

I'd like to do something like this in my Blade pages:

<div class="accordion-content">
    @mdsnippet('snippets/common/some-content-for-multiple-pages.md')
</div>

and then _snippets/common/some-content-for-multiple-pages.md contains:

## here's some content

which Hyde writes out to the output directory as:

<div class="accordion-content">
    <h2>here's some content</h2>
</div>

Is this possible? It looks like we can add Blade in Markdown files:

.x/advanced-markdown

But I'm wanting to do the reverse - Markdown in Blade files.

I'd like to do something like this in my Blade pages:

<div class="accordion-content">
    @mdsnippet('snippets/common/some-content-for-multiple-pages.md')
</div>

and then _snippets/common/some-content-for-multiple-pages.md contains:

## here's some content

which Hyde writes out to the output directory as:

<div class="accordion-content">
    <h2>here's some content</h2>
</div>

Is this possible? It looks like we can add Blade in Markdown files:

https://hydephp/docs/1.x/advanced-markdown

But I'm wanting to do the reverse - Markdown in Blade files.

Share Improve this question edited Feb 20 at 10:35 hakre 198k55 gold badges447 silver badges854 bronze badges Recognized by PHP Collective asked Feb 20 at 8:13 SamSam 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I'm the creator of HydePHP. This is indeed possible. While there is no built-in Blade directive for this (maybe we should add one!), you can easily accomplish this by simply using some PHP code to get a file's contents and compiling it to Markdown. HydePHP does include helpers in the Markdown class.

Take this for example:

@extends('hyde::layouts.app')
@section('content')

    <div class="prose">
        <h1>{!! \Hyde\Markdown\Models\Markdown::render('**Markdown** in **Blade**!') !!}</h1>

        {{ \Hyde\Markdown\Models\Markdown::fromFile(\Hyde\Hyde::path('resources/example-markdown.md')) }}
    </div>

@endsection

This will take the file contents of the file in the resources/ directory (or whichever you choose) and compile the Markdown to HTML and put it in your Blade view!

You can of course also create your own Blade directive, or use a package. Though this is a great feature for us to include in HydePHP itself.

本文标签: phpMarkdown snippets in HydePHPStack Overflow