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

Changing from init() to start() causes error: "Cannot find template with ID main" #340

Closed
gordon-matt opened this issue Jul 4, 2017 · 2 comments

Comments

@gordon-matt
Copy link
Contributor

I was trying to implement save to backend as per issue #73. However, I ran into some errors:

When I try using the .start() method instead of the init() method, I get the following error:
Missing initialization hash, redirecting to main entrypoint

and tracked it back to this error:
Error: Unable to process binding "template: function(){return 'main' }"
Message: Cannot find template with ID main

My code is as follows:

plugins = [
    // plugin for integrating save button
    function (viewModel) {
        var saveCmd = {
            name: 'Save',
            enabled: ko.observable(true)
        };

        saveCmd.execute = function () {
            saveCmd.enabled(false);
            viewModel.metadata.changed = Date.now();
            if (typeof viewModel.metadata.key == 'undefined') {
                var rnd = Math.random().toString(36).substr(2, 7);
                viewModel.metadata.key = rnd;
            }

            // This is the simplest for sending it as POST
            var postData = {
                //csrf_token: 'yourCsrfValueHere', // this is only required if your back-end requires csrf token
                metadata: viewModel.exportMetadata(),
                content: viewModel.exportJSON(),
                html: viewModel.exportHTML()
            };

            $.post('/mosaico/save', postData)
                .done(function () {
                    viewModel.notifier.success(viewModel.t('Successfully saved.'));
                })
                .fail(function (jqXHR, textStatus, error) {
                    console.log(textStatus);
                    console.log(error);
                    console.log(jqXHR);
                    viewModel.notifier.error(viewModel.t('Saving failed. Please try again in a few moments or contact us.'));
                })
                .always(function () {
                    saveCmd.enabled(true);
                });
        };

        viewModel.save = saveCmd;
    },
];

var ok = Mosaico.start({
    imgProcessorBackend: basePath + '/img/',
    emailProcessorBackend: basePath + '/dl/',
    titleToken: "MOSAICO Responsive Email Designer",
    //onSave: function (saveObject) { alert('hi'); },
    fileuploadConfig: {
        url: basePath + '/upload/'
    }
}, '/templates/versafix-1/template-versafix-1.html', undefined, undefined, plugins);

Any help much appreciated

@bago
Copy link
Member

bago commented Jul 4, 2017

If you use start you can't check the return value as start doesn't return false or true.
So your editor.html will always tell you "Missing initialization hash, redirecting to main entrypoint"

@bago bago closed this as completed Jul 4, 2017
@gordon-matt
Copy link
Contributor Author

@bago Thanks for the help. I now have a fully working backend in .NET Core. For those interested, you can find it here

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

2 participants