amaelftah/laravel-trix

Render output

simongeau opened this issue · 9 comments

Is there an easy way to render the content of the editor (outside of a form) ?

@smdimagerie try dd($post->trixRichText->content);

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") !!}

@smdimagerie probably i will try to add a method or document how to get the plain content outside trix editor

trixRichText() is a morphMany relationship, so

$post->trixRichText->content

cannot work. You need to add first() in there as well

@snapey thanks for the help

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;
    }

Hello, is there a way to render the images without being wrapped in an anchor tag? Also, is it possible to hide the caption for the image? Thanks.

Screenshot 2020-06-16 at 15 20 41

You can just do something like this in the controller:
`
$imgUrl = $data->url;
return view('someimagep-page', compact('imgUrl'));

`

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 !!}