laravel-trix icon indicating copy to clipboard operation
laravel-trix copied to clipboard

Render output

Open simongeau opened this issue 4 years ago • 9 comments

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

simongeau avatar Mar 08 '20 18:03 simongeau

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

amaelftah avatar Mar 08 '20 22:03 amaelftah

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

simongeau avatar Mar 09 '20 12:03 simongeau

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

amaelftah avatar Mar 09 '20 21:03 amaelftah

trixRichText() is a morphMany relationship, so

$post->trixRichText->content

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

snapey avatar Mar 17 '20 16:03 snapey

@snapey thanks for the help

amaelftah avatar Mar 17 '20 20:03 amaelftah

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

manshu avatar Jun 07 '20 04:06 manshu

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

lartisan avatar Jun 16 '20 12:06 lartisan

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

`

Crazzz0ne avatar Jul 09 '20 06:07 Crazzz0ne

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

franshoekstra avatar Dec 16 '20 20:12 franshoekstra