0

I have this code in html. It works just fine. However i would like the same code to work in web2py view. Please help me make it work in web2py considering there is a certain way of handling the source files in web2py. In my post.html layout view have tried using:

{{response.files.append(URL('http://www.wiris.net/demo/editor/editor'))}}

'<html>
<head>
    <script src="http://www.wiris.net/demo/editor/editor"></script>
    <script>
        var editor;
        window.onload = function () {
            editor = com.wiris.jsEditor.JsEditor.newInstance({'language': 'en'});
            editor.insertInto(document.getElementById('editorContainer'));
        }
    </script>
</head>
<body>
    <div id="editorContainer"></div>
</body>
</html>'

1 Answer 1

1

In the views of any actions that need the editor, you can do something like:

{{extend 'layout.html'}}
<script src="http://www.wiris.net/demo/editor/editor"></script>
<script>
    var editor;
    window.onload = function () {
        editor = com.wiris.jsEditor.JsEditor.newInstance({'language': 'en'});
        editor.insertInto(document.getElementById('editorContainer'));
    }
</script>

If you'd like, you can even put that code into its own view file (e.g., /views/wiris_js.html), and then wherever you need it, just do:

{{include 'wiris_js.html'}}

Also, note that in this case, you can't use response.files because the filename doesn't end with .js, but for future reference, you should not use the URL() function with external URLs -- it is only intended for generating web2py internal URLs.

Sign up to request clarification or add additional context in comments.

5 Comments

hi Anthony. Thanks for your response. I have been trying out what you have shared but it still will not work. The textbox (editorContainer) still does not render the wiris editor. Is there something i am missing?
Sorry, you can't use response.files in this case because the filename doesn't end with .js. So either copy the file into your own static folder and give it a .js extension, or just manually write the <script> tag. Updated the answer to reflect this.
Anthony thanks i figured it out, because the URL does not end with a .js at the end, Web2py could not understand that it is a js file. Hence it could not load the file properly. Also web2py requires that the URL be secure. At the end of the day i used: <script src="wiris.net/demo/editor/editor#editor.js"></script>. Am sure this is not the best solution but it is a start.
web2py doesn't require that the URL be secure, but if your web2py page is served via HTTPS, then most browsers by default will complain if you try to load something via HTTP.
Your solution seems reasonable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.