Embed widgets in html code using the backend

Topics: Writing modules, Writing themes
Dec 18, 2013 at 7:36 PM
Edited Dec 18, 2013 at 7:38 PM
Ok, maybe i am going too crazy right now.. but, now i want more from this CMS!! I don't even know if this feature already exists in this or other cms but i will throw it right now!!!!!!!!!!

I want to be able to create a widget, for example, a time widget ( Widget that renders the current date and time). Then, i want to be able to call this widget via html using the backend. For exmple in a bodypart, or textfield with flavor: html. For example, i am the administrator (he does not know anything about razor, but basic html) of the site and i am creating a page where i want to use the time widget, and i want to write something in the bodypart like this:
<div>
 <h1> The current time is:</h1> @TimeWidget 
</div>
Where the @TimeWidget is the widget that renders the date and time. The final output should content all the inner html of the widget and call all the drivers and handlers it needs.

It would be awesome, because i am not limited to a specific zone. And the admin would have more tools to work with when creating interactive content. Even for designers it would help. I am just trying to make reusable code.

This idea just came to me because i have been creating a feature to allow front-end users to upload resumes in several websites. This feature comes with different designs and sometimes the requirement comes in flavors in which the upload feature has to be in certain place, inside a specific div. So i can't just create a widget and then pick it, it will not fit the design requirements.

Should i have to rewrite the BodyPart to allow this feature? or create my own BodyPart? add another flavor? snippets?

I am open to listen to anyone's ideas!!

Thanks for your time!
Dec 24, 2013 at 11:40 AM
Have the same idea.
Stuck with how to get widget markup inside module.
Dec 24, 2013 at 12:47 PM
One easy way to implement this could be by implementing an IHtmlFilter (which is processed for BodyPart and Textfields). Inside this filter, you would search for your Widget identifiers, and for each identifier it finds, use the ContentManager to either load an existing widget by name, or instantiate a new one (depending on your needs), build the display shape using ContentManager, and render that shape to HTML. Then replace the widget identifier with that HTML. Done.
Dec 30, 2013 at 12:11 PM
Great! Thank you very much!

And what is the correct way to get html from object ?
I do like this:
var widget = contentManager.BuildDisplay(widget);
And then I did:
var markup = widget .Content.Items[0].Html;
Is this a correct way to get markup ?
Dec 30, 2013 at 1:40 PM
I found )
var markup = ((ContentItem)w.ContentItem).As<BodyPart>().Text;