Render output
simongeau opened this issue · 9 comments
simongeau commented
Is there an easy way to render the content of the editor (outside of a form) ?
amaelftah commented
@smdimagerie try dd($post->trixRichText->content);
simongeau commented
It did not work...
but I did add a new method to the post Model
public function trixRender($field)
{
return $this->trixRichText->where('field', $field)->first()->content;
}
and render using
{!! $post->trixRender("content") !!}
amaelftah commented
@smdimagerie probably i will try to add a method or document how to get the plain content outside trix editor
snapey commented
trixRichText()
is a morphMany relationship, so
$post->trixRichText->content
cannot work. You need to add first()
in there as well
manshu commented
I fixed this $post->trixImageRender('content')
for images too.
Following is my code.
public function trixRender($field)
{
return $this->trixRichText->where('field', $field)->first()->content;
}
public function trixImageRender($field)
{
return $this->trixAttachments->where('field', $field)->first()->attachment;
}
lartisan commented
Crazzz0ne commented
franshoekstra commented
For anyone having the same issue.
To get the content into the view for a normal visitor, this seems to work:
{!! $ridingarena->trixRichText->first()->content !!}