2

Is it possible to enter non-rich-text into the text editor? The apostrophe-rich-text editor seems to add <p> tags around everything inside it. I'd like to format the widget.html like so:

<h2>{{ apos.singleton(data.widget, 'section-heading', 'apostrophe-rich-text') }}</h2>

but the output wraps the text in <p> tags so they override the <h2>. Is there any way to override this behavior?

aklouie
  • 31
  • 3

1 Answers1

1

I figured it out. You have to use the "string" type in the index.js. For example in the /widget-name/index.js, you would put:

module.exports = {
  extend: 'apostrophe-widgets',
  label: 'Section Heading',
  addFields: [
    {
      name: 'sectionHeading',
      label: 'Section Heading',
      type: 'string'
    }
  ]
};

Then, in the /widget-name/views/widget.html, put:

  <h2>{{ data.widget.sectionHeading }}</h2>

This will bring up a dialogue box with a text field labelled "Section Heading". When you save the dialogue box, the string will render on your site.

aklouie
  • 31
  • 3
  • That's correct! Currently there is not a way to edit a simple string in context, like you can with a rich text widget. There are some clunky ways to implement this by using the rich text editor, but a simple in-context string editor would be a nice thing to add. – Alex Gilbert Apr 14 '17 at 20:25
  • can this widget be made generic? I want to avoid creating separate widgets for each and every editable text because the label and name are hardcoded – hussainb Mar 21 '19 at 10:19