-
Notifications
You must be signed in to change notification settings - Fork 504
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
What is the easiest (best) way to store edited newsletters on the backend instead of localstorage #73
Comments
I don't know if my solution is the best, i started hacking mosaico 2 weeks back and i made some improvements. |
Did you do this in index.html? Do you have a repository or a gist to show how you did this? How do you handle "save" button of mosaico? |
Refer to @bago comment on #18 . I followed his advice. and |
We probably can make this simpler by merging metadata+content in a single object and by providing a simple "storage" plugin solution for which "localstorage" is the bundled implementation but it should be easier to plug-in a custom implementation (most people will have to do that). But I'm also happy that we didn't have anything "pluggable" so that some people have to put their hands in the code! I'm happy to see how other developers hack in the code and understand what they expect there ;-) |
This is by far my implementation. I implemented the Save button as plugin. This implementation does not involve localstorage which means don't put hash in your url like: http://youurl.com/editor.html#hashere, just the http://youurl.com/editor.html. it's because mosaico automatically loads the localstorage plugin whenever they found a hash in the url. I hope this helps.
|
This feature alone would make this application 100x more useful. |
@jbaltero Thank you for posting that plugin, it is a lifesaver and super educational. |
@jbaltero you can use Mosaico.start method instead of Mosaico.init if you don't want to enable the "localstorage" built-in plugin login. |
Newbie dev here. How do I implement this plugin? Should I just replace the |
@GLenotre I was just working on this myself. You're supposed to put it in your editor.html file where Mosaico gets initialized. See line 40 where the plugins variable is commented out. Put the plugins array right there, and it will be included when Mosaico is initialized. BUT I was actually having trouble getting it to work. The save button still isn't firing the plugin function, and I'm getting no errors. I don't know if there's anything further you have to do to get it to fire beyond what's posted up there, but any help from @jbaltero or @bago would be infinitely appreciated. |
@GLenotre , @CaptainHypertext is right, go check editor.html line 40 and you should be able to get how it was implemented. @CaptainHypertext what do you mean by save button isn't firing the plugin function? You mean the ajax? Have you debugged it by a simple jquery alert();? |
Thanks for replying,
Mosaico is loading just like normal, and when I click Save, it seems to just do the normal save function, and fires no ajax, and logs no |
@CaptainHypertext Have you checked your URL? make sure it doesn't contain a hash character like http://youurl.com/editor.html#hashere. |
If you don't want the "localStorage" plugin in the way just use Mosaico.start instead of Mosaico.init. Mosaico.start({ yourmosaicooptions }, 'yourtemplatepath', undefined /* metadata */, undefined /* model */, extensions); |
Ah, yes, thanks guys. I think I'm starting to understand this a bit better. Yes, I was still using the hash in the url. I removed that and started using the On the other hand, I've lost the Test and Download buttons (I can live without them for now, though). |
The other buttons are enabled by the "localStorage" plugin that you disabled. https://github.com/voidlabs/mosaico/blob/master/src/js/ext/localstorage.js#L25 |
PS: I admit the test and download buttons do not belong to the localstorage plugin... we need some refactoring to sort this stuff out. I'm on a bigger issue right now but I hope I will be able to put some order here too in the next months. |
Awesome, thanks for the link, I appreciate the help! |
I'm using @CaptainHypertext code above, but I get this error: "Uncaught TypeError: Cannot read property 'template' of undefined". The reference is to template-loader.js:160. Template-loader.js at line 160 says I should add that none of the JS appears on myurl.com/editor.html, just a background color.. |
I'm still having trouble implementing the plugin. In particular, when I navigate to myurl/editor, I get kicked back to myurl. What's wrong with my code below after
Thanks in advance! |
If you are reimplementing the storage then you'll have to put some login in your editor.html so to load the model+metadata and pass this information instead of "undefined"s in your Mosaico.start call. The way you are starting mosaico you are not telling Mosaico what template to use and what content to start with. |
I wrote a backend in PHP/MySQL that can save, load and modify Template data / metadata. I also re-implemented features that were originally dependent on localstorage. Message me if you would like the source, I'm not too familiar with GitHub so I'm not sure exactly how to share it on here. |
Thanks for the sample code. I have written a backend for a Java web application to store newsletters there and load them again. One thing I am still missing though is a way to name these templates. I am thinking a little dialog box like when sending a test mail would be the simplest way to implement this. Has anybody done this before? |
@emu42 What I did is: the mosaico is in an iframe and the parent contains a textfield for name. It's just a quick fix though not directly on mosaico. |
I also have Mosaico inside an IFrame, but placing the text field for the name outside it seems like an awkward solution. So I'm currently looking through the Mosaico code and hoping to figure out how to do this... |
Looking at the email prompt, I now have a few lines of code like this:
However the |
global = window |
So simple when you know it... ;) Thanks! I added the name to the POST data. Seems to work fine. |
Here is a PHP/MySQL solution that saves / loads the template data from the backend. You still need to build Mosaico normally, but this example should help some people out. I also migrated Testing / Exporting away from localStorage. PHPMailer is also used in place of NodeMailer. You can find my fork here: Mosaico + Template Backend |
@jbaltero @CaptainHypertext @notchris I saw your soultions to save email template , I implemented plugins code in my editor.html and use Mosaico.start method. But 'Save' button is not displaying on my editor. here is my code,
I know I have to change in saveCmd.execute and $.post but right now my problem is my editor don't even show save button. |
Do you see the download button? Does everything else works? Do you see errors in the browser javascript console? Add a console log after "viewModel.download = downloadCmd;" so you know that the code is executed. |
@ShahVivek |
@notchris I checked your code , but actually i am implementing it in .net. |
@bago I am not able to see download button. Everything else is works fine. I added console log after "viewModel.download = downloadCmd;" and it prints successfully.
|
You probably altered the template code and broke it: "found unexpected -ko- attribute in compiled template sideArticleBlock-show". Don't mix too many changes if you want to be able to debug. So, try altering the save button without altering the rest of mosaico or the template. |
If I take the time to write a tutorial for implementation with different backends, can it be posted on the main page? |
Can't promise anything before I see the result. |
I have successfully implemented a full PHP backend with saving and loading all done server side. I will issue a pull-request next week after some more testing. |
Do you have this backend? |
+1 Also interested in the php backend with storage |
My example is a working php backend with storage @janober @webportpl |
@mattghall I will be interested in who you successfully implemented a full PHP backend with saving and loading all done server side. |
When I try using the and tracked it back to this error: My code is as follows:
Any help much appreciated |
You are just awesome . Did the most of it and that was a quick starter. |
@athulhere Glad it helped! I haven't updated it in years so I'm happy it is still working. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
What would be the easiest way to replace localstorage by a backend
As far as I can see, it requires following steps
It appears to me that the latter issue needs to be done in index.html as well as in mosaico respectively in editor.html. Could we find another appraoch, for example:
Of course beyond these basic things, one could think of more advanced scenarios, but this might be discussed #50 resp. #59
The text was updated successfully, but these errors were encountered: