Reputation: 83
I'm building a kind of content manager for a website. Whay I need is to have a field in a form where I can put formatted text. Then I want to be able to persist it to the DB and then when the entity is displayed, I have to render it with the format!
Any clues in how to do that?
I looked in the Tinymce editor, (stfalcon's bundle) but I don't know how to make the editor (which is very nice) fit in my forms. I just displays over the other fields of the form that i have...
Upvotes: 0
Views: 1797
Reputation: 934
To do that you do not need to use any bundle. You can implement a jquery text editor, such as redactor, ckeditor..
In your FormType just pass a class variable which appropriate with your wsyiwyg editor. For example you use Redactor to make it possible.
<script type="text/javascript">
$(document).ready(function(){
$('.redactor').redactor();
});
</script>
In your FormType you must build a textarea with a class "redactor". To do that:
$builder->add('content', 'textarea', array('label' => "Content", 'attr' => array("class" => "redactor", "style" => "height: 300px")));
Finally, in your Twig print the content row:
{{ form_row(form.content) }}
Upvotes: 4