1

Maybe I have not understand how entries work but I would like to create a rich text field in my plugin without having an entry.

All I want is creating a rich text field with twig but how can I do this? I already read this https://craftcms.com/docs/rich-text-fields but it was not really helpful. I would just like to have something like this just for a rich text field instead of a normal textfield

{{ forms.textField({
    label: 'Ingredient Name'|t,
    required: true,
    name: 'ingredient[name]',
    value: ingredient ? ingredient.name : null,
    errors: ingredient ? ingredient.errors('name') : null,
 }) }}

Could someone please help me?

if I make {{ entry.richTextFieldHandle }} I get the error Variable "entry" does not exist and I don't know how to define entry since I don't use an entry. Do I have to include my own redactor.js if I just want to have an html editor?

1 Answer 1

3

If you want a rich text field on a front end - this question has been answered in detail here: How do I enable redactor rich text editor in a front-end form?

In short technically possible but not recommended.

If you want a rich text field for a back end, i.e. plugin, form:

The craft macros for form fields live in craft/app/templates/forms - however I do not believe there is a macro for a rich text field. There are text and textarea macros you can use.

However, I think it is possible in a plugin - this apparently creates a rich text field widget in your craft dashboard, so you should be able to pinch the relevant code from: https://github.com/gilleard/RichTextWidget/blob/master/richtextwidget/widgets/RichTextWidget_DashboardWidget.php

(Specifically look at public function getSettingsHtml() I think)

3
  • Well I don't want to have it as a front end resource I just don't really understand how to use it in my backend since I don't have the variable entry or another variable similar to it. But thank you. If craft is unable to create a rich text editor itself, I'll use this method Commented Nov 18, 2016 at 7:07
  • Oh sorry, my mistake, I missed the plugin bit. It should be fine in that context. I'm away from keyboard now but I'll look through the form lib later Commented Nov 18, 2016 at 7:13
  • I've revised my answer above ... there's no out of the box macro for you, I think, but it looks like it is possible - see the plugin I have linked above. Commented Nov 19, 2016 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.