Skip to content
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

How to output Markdown content as raw HTML? #185

Closed
minthemiddle opened this issue Feb 23, 2018 · 3 comments
Closed

How to output Markdown content as raw HTML? #185

minthemiddle opened this issue Feb 23, 2018 · 3 comments

Comments

@minthemiddle
Copy link

minthemiddle commented Feb 23, 2018

I have problems outputting the content of a collection's Markdown as pure HTML.
When I use {{ $collection->getContent() }} I get "<p>My content</p>" which literally outputs the HTML tags. When I use the blade raw directive: {!! $collection->getContent() !!}, I get the right result, but it this the best practice?

I use the content block in a partial and cannot use the @yield() command in that scenario I guess.

@damiani
Copy link
Contributor

damiani commented Feb 23, 2018

The typical setup would be to extend a parent template from each of your collection items, and render the content using @yield(); if you're doing something else that requires you to access $collection directly, then yes, {!! $collection->getContent() !!} would be the best way to output the processed Markdown content.

If you have a repo of your project I can take a look at, I can give you more specific advice...there may be a better way to structure your collection files.

@minthemiddle
Copy link
Author

Thanks for the feedback. We are using markdowns in a collection to add updates to youth camps that we run. This is the repo: https://github.com/CodeDesignInitiative/cdweb1801

Each camp is an own markdown from the camp collection which extends an layout. In this layout, we include an update.

The update pulls an entry from the update collection and compares the camp ids (e.g. ber1802) and shows the corresponding update.

I guess that in this setting, I cannot extend on an layout and need to to refer to {!! $collection->getContent() !!}.

@damiani
Copy link
Contributor

damiani commented Feb 27, 2018

Yes, if you're referencing an item directly, like you are with each update, you need to access its content using getContent.

But I've just added support for the ability to drop the ->getContent() part in a Blade view, in this PR. Once that's merged, you'll be able to simply call {!! $update !!} in your Blade template.

@damiani damiani closed this as completed Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants