How to load content from db to trix, to edit existing content?
filipdak opened this issue · 9 comments
Hello,
Everything works fine, but cant figure out one think - how to load content to trix editor?
I made in app option to create and edit article content. For example here I geting passed to view title:
<input type="text" id='title' name='title' value="{{$article->title}}"></br>
But how load title to trix, to have chance to edit it using wysiwyg?
@trix(\App\Article::class, 'title')
Thanks for quick anserw, but still one thing - render methods loads content from db table trix_ritch_texts? In my case render methods show only wysiwyg editor but no content included - i think the problem is that my articles are stored only in articles table and trix_ritch_texts is still empty.
@filipdak i think this is the reason . maybe i will try to implement a feature to solve this problem but for current time i have two thoughts on that .
-
first you can move the content of articles table to trix_rich_texts table .
-
second you can abandon trix package for now till i figure something that only renders text if it's not from DB
This work for me!, in my blade file
Show Video: https://www.loom.com/share/7ce5f1a4c7b34d5f878a9e2fb3825df4
<script type="text/javascript">
function setValue(text = '') {
const trixEditor = document.querySelector("trix-editor")
trixEditor.editor.insertHTML(text);
}
document.addEventListener("DOMContentLoaded", function (event) {
setValue('HERE MY DATA RAW HTML')
});
</script>
@leifermendez thanks for sharing
@leifermendez your approach won't work if you use any sort of HTML string as setValue
argument. In order to insert a string containing special chars into Trix text box (from Laravel model), you must do some weird stuff like that:
setValue( atob( "{{ base64_encode($contents) }}" ) );
{!! Form::hidden('content', null, ['class' => 'form-control', 'id' => 'emailTemplate']) !!}
<trix-editor input="emailTemplate"></trix-editor>
use like the above.
Trix method is not working properly when editing the existing data
@trix(\App\Article::class, 'title')