dotCMS / core

Headless/Hybrid Content Management System for Enterprises
http://dotcms.com
Other
846 stars 465 forks source link

Create an example custom field that uses a React component/App #19414

Closed wezell closed 3 years ago

wezell commented 3 years ago

What we need is an example on how to write a custom field in dotCMS using another javascript framework, Vue or React.

The pattern would be to implement a component that runs in an iframe and takes and sets the custom field's value

  1. Learn about how custom fields work in dotCMS: https://dotcms.com/docs/latest/custom-field

  2. Implement a React Component that either had a Markdown Editor or a different WYSIWYG which the user could use.

  3. Write some rough documentation on how you did it.

alfredo-dotcms commented 3 years ago

DotCMS Custom Field with a ReactJS app SimpleMDE - Markdown Editor

The following are instructions to create a custom field in DotCMS using a VTL file that can import a ReactJS App (any JS framework app could be imported using the same principle) into an Iframe.

Steps:

  1. Create the Custom Field
  2. Create the VTL file
  3. Create and build the ReactJS app
  4. Upload the ReactJS app
  5. Create a content based on the new Custom Field

1. Create the Custom Field

2. Create the VTL file

3. Create and build the ReactJS app

***Notes:** on `line 13` the `Custom Event` name must match with the name declared on step [2. B](#step2b)

- D) In your terminal build your ReactJS App:

npm run build;



### 4. Upload the ReactJS app
- Grab all files and folders from the folder `build` and upload them into the DotCMS server.
***Notes:** The location must match the one defined on the VTL file on `line 16` on step step [2. B](#step2b)

### 5. Create a content based on the new `Custom Field`
- A) Go to `Content` --> `Search` and add a new Custom Content created on step step [1. B](#step1b)
wezell commented 3 years ago

Repo found here: https://github.com/dotcms-plugins/custom-field-react

alfredo-dotcms commented 3 years ago

dotCMS Custom Field - React Markdown Editor

This example shows to create a custom field that leverages prebuilt react components - in this case, the SimpleMDE - Markdown Editor

The patterns that this plugin uses to enable this react component can be used to incorporate any 3rd party javascript component (NG/Vue/React based) as a content control. It uses a .vtl file to render the custom control in an iframe on the content editing screen and writes any changes made in the editor to the content's custom field value.

Steps:

  1. Clone and build the ReactJS app
  2. Upload the ReactJS app into dotCMS.
  3. Create the Custom Field
  4. Create a content based on the new Custom Field

1. Clone and build the ReactJS app

2. Upload the ReactJS app into dotCMS

3. Create the Custom Field

4. Create a content based on the new Custom Field

alfredo-dotcms commented 3 years ago

@wezell I just simplified the steps (previous comment), please take a look and share some thoughts: https://github.com/dotCMS/core/issues/19414#issuecomment-730029111

Repo with simplified folder structure & files: https://github.com/dotcms-plugins/custom-field-react

wezell commented 3 years ago

Nice, thanks @alfredo-dotcms !