How to convert theme to BlogEngine.NET part 4

16. September 2010 11:20 by rtur.net in Themes  //  Tags: ,   //   Comments (22)

menu- 1

In this part we'll get menu working. BlogEngine supports “pages” – pages are different in that they don’t belong to post list, don’t support comments and can have parent/child relationship. In short, this is a way to turn your blog into CMS (content management system) or combine blog and CMS on the same site. BlogEngine has page list widget that shows list of all pages on the site. It is a simple flat list and does not support nesting, that is why a while back I wrote this control to extend standard list to hierarchical unsorted HTML list that can be styled with CSS to look as horizontal or vertical menu usually used in CMS-style websites.

Adding horizontal CSS menu

Boldy has dropdown menu on top, it actually uses Dynamic Drive’s smooth navigation menu – which is perfect, because I can use my old menu control to generate unsorted list and take CSS and JavaScript that came with Boldy pretty much unchanged. Steps I went through:

  1. Compared HTML generated by my page menu control with one required by smooth navigation menu. Needed just remove “span” inside link to get it matched.
  2. Added blog:PageMenu control to the site.master and added reference to CSS style that Boldy uses to style the menu.
  3. With JavaScript it is a little trickier, you can’t reference script inside your theme because BlogEngine uses HTTP handler to compress and validate JavaScript and your reference will be ignored. To get around, you’d have to either add inline script or use extension to inject reference into the header at runtime. However, the easiest way is to add this reference in the admin/settings/tracking script, and that’s what I did. It will make script site-wide, but if you only using one theme it does not matter and it is small overhead even if you switch to the another theme and forget to remove it later on.
  4. I trigger JavaScript in the body-on-load and added small function to the script that I call from body load event.
  5. Added login link to the menu.

That is it. To summarize, control generates UL, it is styled with style that came with Boldy and sliding effect provided by JavaScript that also came with Boldy, pretty simple.

PageMenu control is very basic, it adds home/archive items in the beginning and contact/logoff in the end. If you want to remove, add or modify any of those, you need to open control’s file in the text editor (/app_code/controls/PageMenu.cs) and remove or comment out some code. Fore example, removing this line will get rid of “Contact” item in the menu:

AddMenuItem(ul, Resources.labels.contact, "~/contact.aspx");

To install or update theme:

  1. Copy “Bodly” folder into /themes folder
  2. Copy PageMenu.cs into /app_code/controls folder
  3. Add script reference (below) to the admin/settings/tracking scripts
<script type="text/javascript" defer="defer" src="/blog/js.axd?path=/blog/themes/Boldy/js/ddsmoothmenu.js"></script>

You have to modify “path” in that script to match your site. If it is in the root, it will be just “/js.axd?…” etc.

Login links pointed to "/account/login.aspx" - you might need to change it to "/login.aspx" for your version, it moved to "account" only recently.

Boldy4.zip (1.77 mb)

Comments (22) -

John
John
9/22/2010 8:18:45 PM #

I've been following along, reading the series and I am impressed with what you have done. It's pretty easy to follow and I appreciate your work.  One quick question... To implement boldy, should I start back with version 1 or can I start directly with the latest version?

rtur.net
rtur.net
9/22/2010 10:28:36 PM #

If you want to implement it for your blog, you can just grab the latest. Other downloads meant for someone who wants to check how theme evolved and things been added to learn how to create/convert themes on its own.

John
John
9/23/2010 11:05:11 AM #

Ok... I must be missing something. I've been following along since part 1, but with the latest version I'm running into a script error. I have a brand new BE 1.6.1 install, putting boldy4 in place I get a script error now. It's most likely the tracking script for the ddsmoothmenu and the path, but I can't get it to register no matter what I put in for the path. The site is only the blog, so it is the root web. You can see it here...  http://capricornhorse.net

I don't know if it's related, but the nice search animation doesn't work either.

Any help would be greatly appreciated...

rtur.net
rtur.net
9/23/2010 12:08:10 PM #

Hi John, you seems to be missing jQuery - BE did not have it in 1.6.1 yet, you need to add it to your site for animation effects to work. Also, you might need to add slash in front of "js.axd" in the menu script (make it "/js.axd....").

That ajax spinner on your form - add this to CSS to turn it off:

#commentPreview { display: none; }

John
John
9/23/2010 12:38:25 PM #

Thanks for the assistance.  Once I got jQuery loaded, everything started working. I also got the spinner taken care of... It's been a while since 1.6.1 came out and keep looking for a new release (maybe soon?)

John
John
9/24/2010 8:55:34 PM #

Just a quick follow up... I got everything working (thanks for your help).

One note...
Have you used boldy with the latest version of BE (1.6.2.6)? I was playing today and got server 500 errors whenever I tried to use boldy with that build. I didn't dig into too much (not enough time).

I'm really liking what I saw in 1.6.2.6...

rtur.net
rtur.net
9/29/2010 10:36:43 PM #

Yes, there's been couple breaking changes to public interface. I'm working on fixing it on BE side.

James
James
9/29/2010 6:27:38 AM #

Im having problems with jquery, dont know why its giving me problems, I have 2 other jquery scripts also on page, not sure if there is a confilct between the two, :(

Kuman
Kuman
10/23/2010 4:31:53 PM #

You have to modify “path” in that script to match your site.

How to modify it?

Ahmed
Ahmed
10/26/2010 2:59:17 AM #

Hi,
Thank you for time and your great posts.
I'm new to BE and C#, i'd like more details if you don't mind :)

I applied your Boldy4 folder to a test blog. When i run the application i got an error, details shown here http://img547.imageshack.us/img547/4300/boldyblogerror.png

i'd appreciate any help.
Thanks

Rasch
Rasch
11/12/2010 12:17:12 AM #

I have tried to add your Boldy theme to my blog and having trouble figuring out what to do with the third item on your ReadMe.txt list?

Hope you (or someone else) can help me out here :-)

Also, how can I make the initial home-page of the Boldy WP theme? Any ideas?

Rasch
Rasch
11/12/2010 12:20:30 AM #

Disregard the part about the tracking scripts, I just figured that out now ... problem due to stupid user :-(

But if you got any input as to making an initial page like the one on the WP version, I would apreciate it.

John Arheghan
John Arheghan
11/16/2010 4:00:36 AM #

I am new to Jquery and i was in-trigged by how you implemented the jquery engine on your blog. I have followed your examples and read through the step but I am still having the "error 'null' is null or not an object" when I run the BE on my local machine.
I can find the admin/settings/tracking scripts folder on the BE 1.6.1. Should I create this folder or is it something different. I need you to enlightening me on this.
Thanks  

rtur.net
rtur.net
11/17/2010 12:16:07 PM #

No, it is actually not a folder path. Just go to admin panel in your BE site and navigate to settings section, find text area for tracking scripts and paste script in there. Sorry for confusion.

John Arheghan
John Arheghan
11/20/2010 2:26:40 PM #

It is working perfectly. Thanks for the info. I was having a little problem using the PageMenu control you build. It does come up on the page but am having problems trying to make it fit in my page. How do you manipulate the size and color of the menu? is it through the CSS?

Jones
Jones
12/1/2010 2:51:28 AM #

I read all the other part of this post and after reading this part, i cant stop myself from commenting on this. I must say it is a excellent post and very helpful. I wanted to convert my theme into BlogEngine.Net but not getting how to do it. After reading your post, my all doubts are cleared. Thanks for sharing this.

Magnus
Magnus
1/6/2011 4:27:58 PM #

I thought this looked real nice and wanted to try it...but I have BE 2.0.0.36 with ASP.NET 4 installed so i'm not sure where to put the reference because the structure is a little different...any ideas?

When I have figured that part out I will make a few themes of my own and also adapt a WP theme as well.

Thanks

rtur.net
rtur.net
1/6/2011 5:48:53 PM #

There is "custom code" section in the admin, reference goes there. Usually I add it to the "trailing" textbox, but adding to the header should also work.

Guy
Guy
1/23/2011 8:03:52 PM #

This is probably a stupid question, but how can you make the menu and logo reverse places? I had a look in the site.master page but the logo DIV comes before the mainMenu DIV.

Thx. Like your blog, one of the most informative on BE I've come across.

rtur.net
rtur.net
1/23/2011 9:30:22 PM #

If you check CSS file, they have absolute positioning with menu top set to 0 and logo to 90px. Swap that, and they change places - but you likely will run into more issues after that because other elements might depend on these two.

Guy
Guy
1/25/2011 5:42:19 AM #

Yes - that worked. I had to play around with the .css file a bit to get everything else in place but it's as I want it now. Thx.

mike brown
mike brown
2/13/2011 3:54:52 PM #

Very useful! This is something i've been pondering about. staying up for reading more next month.

Comments are closed