This project is read-only.

widgets, extensions and a dumb question or two...

Oct 1, 2008 at 1:08 PM
I've now several sites running this rather nifty pisce of software, so I think it's time to up my game a little. Perhaps someone here can help. I only have the free Visual Web Developer program, hence I can't do stuf which requires me to recompile any libraries ...

I can see that I can use widgets to insert my own html into the place where the widgets live (the sidebar). I create a text box, then switch to html and I can put whatever I want in there. That's neat.
Dumb Question 1:
There's a control in my theme's master page called "WidgetZone" which seems to be the container for these. Ok, that makes sense. Can I have more than one of those widget zones on a master page? I can try it, but I have other questions...

User Controls
I can see that I can create user-controls, which I can distribute around my theme master page to get server-side logic into the page. That's neat too. So if I can't achieve what I want with client-side html (as above), then I can squirt it out with the theme master and that will do the job. Less flexible than the "widgets but should do the job.
Dumb Question 2: is there any way I can put my own user-control inside a page? In the content, not the master I mean.
Let's say I have a control which embeds a little scrolling slide-show for example. I'd need to have a parameter which I use to control which pictures are shown, and I'd need a way of inserting that control into the page via the editor. Can that be done, or are user controls limited to the master page?

Then we have extensions... those look rather powerful and I've read what I can in the Wiki.
Dumb Question 3:
Is there a list of the events I can hang these off? I'm just trying to understand what I can use these for, and I think I missed something somewhere.

Theme Switching
Ok I admit that I've not searched for this one yet but I just realized I'd like to do it and you'll ignore it if it's already been covered anyway...
I have multiple sites each of which has it's own theme. I've seen (although not made work particularly well) the theme "preview" feature so I know the theme is fairly dynamically processed.

Dumb Question 4: I have one site which currently has different sections which have different themes - different master pages and different style-sheets to be precise. If I move this site to BE, can I switch theme dynamically depending on which section of the site I'm on? Is there a bit of logic which says: "switchThemeTo( "fancyName");" or some such? If so, I'd need to hook into something prior to processing the master page in order to switch it...?

Anyway, thanks in advance. I'll update the wiki with anything I learn. Unless it's "RTFM" of course.

Oct 1, 2008 at 10:56 PM
Widgets:  Currently you can only have one Widget area loaded.  There might be some custom mods out there but from the BlogEngine group there's only one allowed right now.

User Controls:  You can add User Controls to any page/post by inserting the syntax  [usercontrol: ~/User controls/MyControl.ascx].  If the UserControl accepts optional arguements then you pass them using the syntax:       [usercontrol: ~/User controls/MyControl.ascx Arg1=something;Arg2=something].

Extensions: Extensions can be configured to most anything that involves events of the blog.  You should look at extensions that are already out there to determine how to hook into page and post events.

Theme Switching: If you add the syntax ?theme=MyThemeName to any url address the page/post will be displayed with that theme.  Other than that BlogEngine doesn't include any way to make that option permanent for someone.  You could explore using JavaScript, cookies, and what not, to configure the clients ability to make a theme choice.

Oh, and welcome to BlogEngine.NET!
Oct 2, 2008 at 2:33 PM

Widgets: Ok, I'll ignore those for now.

User Controls: Ok, I can run a user control which takes no parameters just fine, but I get the dreaded "ERROR - UNABLE TO LOAD CONTROL" if I try using parameters. I tried copying my own (known to work) user controls into the right place, creating new controls, and copying the existing controls. All fail in precisely the same way. I built a test control with one public parameter ("public int Width;), but I can't pass "Width" as a parameter. In desperation I though you may mean literally "Arg1", but that didn't work either. I tried adding accessors to the public (which shouldn't be necessary); still no soap. I tried making the test argument a string (rather than an int); still the same error. All upper-case/ lower-case: makes no difference. Separate control name and parameter with colon or semi-colon: nope. I'm running out of variations on this theme...

Does anyone have any examples to help me understand how I pass parameters to user controls? As above, I know I'm loading the control and it loads just fine with no parameters, so my problem is specifically the passing of parameters to the control. I need an example with the precise syntax I think - if there are singe quotes, double quotes, backslashes or chineese characters required, please can you spell those out for me as I can't guess what's required.

Extensions: I've seen some examples, but there are rather a lot of events and they bubble through a large number of different things. Still, if I can't pass a lousy parameter I'm not going to be messing with that for some time.

Themes: I can do that the hard way, no problem. Something in the theme page master ought to do it I'd think.

Oct 2, 2008 at 3:41 PM
Have another look at the syntax I gave as an example:

[usercontrol: ~/User controls/MyControl.ascx Arg1=something;Arg2=something]

Assuming you have your Public variable setup correctly this should work.  I have a couple User Controls on my Blog that have variables passed...

As for events, there's a full list of events on the Wiki page off of the BlogEngine.NET homepage...

Good luck!
Oct 2, 2008 at 4:35 PM
Thanks; I think you can be sure I looked closely enough at it - I even cut and pasted it and tried that, but it didn't work.

The key I think I just found: it's necessary to have an explicit set accessor for the public parameters in order for this to work. That's not strictly necessary in C#/ generally - if for example you have a public property which you just squirt into the code with <%=Arg1%> which is effectively what I was doing in this control. So if you just have a set accessor, it seems to work.

To be absolutely clear:
     public int Height;
will cause the control to fail in BE (but not in other pages).

    private string _unused;
    public string Arg2 { set {  _unused = value;}}

will work.

Phew. Thanks.
Oct 3, 2008 at 9:16 AM
Oh, I found a list of the events here: