Reputation: 1041
I'm trying to use Parsedown in Laravel 5.6.3. As far as I can tell, Composer packages are autoloaded into Laravel, so I should be able to do something like this:
{{ Parsedown('## Hello World!') }}
But when I try that, I get:
Call to undefined function Parsedown().
So I tried to create an object of Parsedown with the following:
{{ $parsedown = new \Parsedown() }}
But then I get
htmlspecialchars() expects parameter 1 to be string, object given
At first I thought it was something to do with Laravel's autoloader, but when I request something from vlucas/dotenv I get the results I expect:
<p>{{ getenv('APP_NAME') }}</p>
outputs Laravel
.
I'm not sure where I'm going wrong. I can't find anything in the Laravel docs to help me out either.
The answer by @AlexeyMezenin is correct, and it answers my original question. However it did not allow my markdown to be rendered. The following two lines are correct and allow markdown to be rendered:
@php($parsedown = new Parsedown())
<?= $parsedown->text('Hello _Parsedown_!'); ?>
It seems that the blade templating engine is having issues with echoing out parsedown. This edit has been added to help other users having the same problem as myself.
Upvotes: 3
Views: 2442
Reputation: 12126
Have you installed parsedown/laravel
using composer? That should solve your problem, as given in the documentation at https://github.com/parsedown/laravel
Upvotes: 1
Reputation: 163898
{{}}
will be rendered to echo
by Blade engine. So, so change this:
{{ $parsedown = new \Parsedown() }}
To:
@php($parsedown = new \Parsedown())
Or:
@php
$parsedown = new \Parsedown();
@endphp
Or:
<?php $parsedown = new \Parsedown(); ?>
Upvotes: 4