1

I recently watched Dav Glass' talk on YUI and node, and the server-side rendering of widgets got me particularly interested.

I want to do something similar, while still being able to use javascript for the widgets on the client side. The problem I am facing is how to run code associated with the widget (adding click events. etc) once the page is loaded.

One way of doing it could be to write an init function for each widget, then turn it into a string and put it in a script-tag along with the rendered html, but I don't think that's a very pretty solution.

Can anyone think of a better solution?

1 Answer 1

1

Have you considered using Dojo? It also has a great widget system and parses the widgets out of the html.

Rolling your own widget system has a lot of complications that you will run into, while building on Dojo will give you a ton of great components to start with.

you can just set dojo djConfig="parseOnLoad:true" in the dojo script tag and dojo will parse your widgets for you.

You can also make your own widgets and do some custom init stuff in the widget postCreate method, which is like your init method you mention.

See this page for more about Dojo widget methods: http://dojotoolkit.org/reference-guide/dijit/_Widget.html

I have built a lot of my own Dojo widgets and really like the framework.

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

1 Comment

While this isn't completely solving my problem (Dojo is not compatible with node out of the box) it gave me inspiration to a solution. When the page loads, dojo traverses the dom tree looking for elements with a dojoType attribute. If the type matches a widget, the widget constructor is called with the dom element as the argument.

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.