Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to support field tokens #59

Closed
gordon-matt opened this issue Jan 19, 2018 · 2 comments
Closed

Trying to support field tokens #59

gordon-matt opened this issue Jan 19, 2018 · 2 comments

Comments

@gordon-matt
Copy link

I am trying to figure out how I can insert "field tokens" in the templates. For example:

Dear {FirstName} {LastName},

Obviously my own backend will replace these tokens with real values before sending the emails. Currently, we will have to ask the users to manually type these tokens.. but that is a problem because they don't know what the possible tokens are. What I want is for a way to pass an array of possible tokens into GrapesJS editor and then the user can choose a token and it will insert at the cursor position. I think I know 95% of the solution already.. I will probably do something like this:

  1. Add a custom button:
editor.Panels.addButton('options', [{
	id: 'show-tokens',
	className: 'fa fa-token',
	command: 'show-tokens',
	attributes: { title: 'Tokens' }
}]);
  1. Add the command
editor.Commands.add('show-tokens', {
	run: function (editor, sender) {
		sender && sender.set('active', 0); // turn off the button
		// TODO: Show some list of tokens (like modal dialog or something...)
	}
});
  1. From modal dialog of tokens, user will select a token (example: {FirstName})

  2. On button click, I want to insert that selected token into the GrapesJS editor at the current cursor position.

So I think I only need help with step 4. How can I insert at current cursor position? Thanks in advance.

@gordon-matt
Copy link
Author

Actually.. I just found that issue 481 in the main repo answers this question, here: GrapesJS Issue 481.

That looks perfect.. except I have 1 quick question... because I am new to Grapes.. What if I replace your RichTextEditor with CKEditor or TinyMCE? Will this solution still work?

@gordon-matt
Copy link
Author

Sorry, never mind... I see there's a solution using a block instead of a rich text editor.. that looks perfect. I will close this issue and try to implement something like I see in that issue I previously mentioned. If I get any problems, I will mention it there, as I see it's still an open issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant