Search Results

Search found 581 results on 24 pages for 'sidebar'.

Page 1/24 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Add the Vista Style Sidebar Back to Windows 7

    - by Mysticgeek
    If you are moving from Vista to Windows 7, you might miss the Sidebar which was introduced in Vista. Today we take a look at a couple options for getting a Sidebar back in Windows 7. Copy Files from Vista Note: In this example we are using 32-bit versions of Vista and Windows 7. Make sure you are logged in with Administrator credentials. If you have a Vista machine running, we can copy the Windows Sidebar files over to the Windows 7 machine. On the Vista machine navigate to C:\Program Files and copy the Windows Sidebar folder and all of its contents over to a flash drive or network location. On the Windows 7 machine go to C:\Program Files and rename the Windows Sidebar folder to something like Windows Sidebar_old. Now copy the Vista Windows Sidebar folder into C:\Program Files… Now you will have both folders…Windows Sidebar and Windows Sidebar_old in your C:\Program Files folder. Right-click on the desktop and select Gadgets. There you are…the Original Vista Sidebar is back and will act as it did in Vista. Move Sidebar Gadgets Another work around if you don’t have a copy of Vista, you can simply move the Desktop Gadgets you want over to the right side of the screen and they will stay there…no dock needed. Type gadgets into the Search box in the Windows Start Menu and click on Desktop Gadgets. Then drag the included Gadgets you want over to the right side of the screen. Or click on the link to Get more gadgets online to find more. Once you have them where you want, each time you reboot they will still be in the same location. This holds true no matter where you place them on your desktop as well. Install Desktop Sidebar If you want an enhanced sidebar that includes a lot of different features, and don’t have a copy of Vista, you might want to check out Desktop Sidebar Beta (link below). This is a freeware application that works with Windows XP, Vista, and Windows 7. After installation you can access it from the Start Menu… Here is how it will look after you launch it… It includes several pre-installed panels including a clock, Media Player, Search Bar, Slideshow, Messenger, Outlook inbox, Tasks, Quick Launch, Performance…and a lot more. It is highly customizable and allows you to change skins, add various levels of transparency, and a lot more. One caveat with going with Desktop Sidebar is we didn’t find a way to add Windows Gadgets to it (though there might be a plugin for it that we’re not aware of). But there are so many options, you may not mind. However, you can still use the desktop gadgets as you normally would in Windows 7. Believe it or not, some people actually prefer the Vista style Sidebar and would like it back in Windows 7. With these options you can get the Vista Sidebar back if you have a copy of Vista, place the Gadgets on the desktop, or go the freeware route. Download Desktop Sidebar (freeware) Similar Articles Productive Geek Tips Disable Windows Sidebar in VistaHow To Repair Your Crashed or Hanging Vista SidebarApplying Themes To Your Windows Vista SidebarDisable Sidebar / Desktop Gadgets on Windows 7Put AOL Instant Messenger (AIM) In your Windows Sidebar TouchFreeze Alternative in AutoHotkey The Icy Undertow Desktop Windows Home Server – Backup to LAN The Clear & Clean Desktop Use This Bookmarklet to Easily Get Albums Use AutoHotkey to Assign a Hotkey to a Specific Window Latest Software Reviews Tinyhacker Random Tips CloudBerry Online Backup 1.5 for Windows Home Server Snagit 10 VMware Workstation 7 Acronis Online Backup Ultimate Boot CD can help when disaster strikes Windows Firewall with Advanced Security – How To Guides Sculptris 1.0, 3D Drawing app AceStock, a Tiny Desktop Quote Monitor Gmail Button Addon (Firefox) Hyperwords addon (Firefox)

    Read the article

  • Rails 3 - yield return or callback won't call in view <%= yield(:sidebar) || render('shared/sidebar'

    - by rzar
    Hey folks, I'm migrating a Website from Rails 2 (latest) to Rails 3 (beta2). Testing with Ruby 1.9.1p378 and Ruby 1.9.2dev (2010-04-05 trunk 27225) Stuck in a situation, i don't know which part will work well. Suspect yield is the problem, but don't know exactly. In my Layout Files I use the following technique quite often: app/views/layouts/application.html.erb: <%= yield(:sidebar) || render('shared/sidebar') %> For Example the partial look like: app/views/shared/_sidebar.html.erb: <p>Default sidebar Content. Bla Bla</p> Now it is time for the key part! In any view, I want to create a content_for block (optional). This can contain a pice of HTML etc. example below. If this block is set, the pice HTML inside should render in application.html.erb. If not, Rails should render the Partial at shared/_sidebar.html.erb on the right hand side. app/views/books/index.html.erb: <% content_for :sidebar do %> <strong>You have to read REWORK, a book from 37signals!</strong> <% end %> So you've got the idea. Hopefully. This technique worked well in any Rails 2.x Application. Now, in Rails 3 (beta2) only the yield Part is working. || render('shared/sidebar') The or side will not process by rails or maybe ruby. Thanks for input and time!

    Read the article

  • Browser tabs creates multuple instances of a sidebar for each tabs. I want only one sidebar for all

    - by BHOdevelopper
    I have a sidebar (iframe). The problem is, if you open a second tab (in the same browser) it creates a new instance of the same sidebar. That means i have now 2 sidebars. In exemple, if i close the sidebar in the first tab, i would like to have it closed in the second tab as well. Is it possible to have only one instance of a sidebar in a browser, so that even if i open a new tab, the sidebar is not affected. (the goal is to interact with evey pages we visit with one sidebar. If anyone need precisions, please ask. I'll be checking for responses every single days.

    Read the article

  • Windows 7 sidebar, where is it?

    - by Martti Laine
    Hello I installed Win7 a while ago, and now I'm wondering if there is no sidebar in Win7? I can't find it, running "sidebar" (win+r) doesn't find it. It's not in the processes either. Is there a way to install it? Martti Laine

    Read the article

  • Firefox- How to change font size of items in bookmarks sidebar

    - by TheClamkinator
    In Windows. (I know I can open Desktop > Properties > Appearance > Advanced [and figure out which item determines it; probably Menu]. But, I don't want other things changed - just the bookmarks. This is because I have so many and I want more of them to display. I did see the question on changing font size of items in folder, on bookmarks toolbar, and sub-folders, etc; But, I'm talking sidebar on firefox, I don't have Google Chrome and I am not a developer.

    Read the article

  • Sidebar for Navigation in Website

    - by Johnson Smith
    I want to have a sidebar in my website with navigation in it. I will use script like phpBB etc. but I want sidebar to be displayed on every page. So I am thinking about making a Sidebar in HTML and then using frame tag for displaying other pages/scripts. But as Frames are getting obsolute, Is there any other method to display a sidebar in everypage without using frames and without adding html coding on every page?

    Read the article

  • Add an item to the Finder/Save dialog sidebar

    - by Clinton Blackmore
    I'm working on a script where a user logs into a guest account on OS and is prompted for their network credentials in order to mount their network home folder (while they benefit from working on a local user folder). As the guest folder is deleted when users log out, I want to discourage them from saving anything there. I would like to replace the items on the Finder and Open/Save sidebar lists (such as "Desktop", username, "Documents", etc) with ones that would save into their network home folder. It is possible to do this using AppleScript or Cocoa APIs, or do I need to modify a plist and restart the Finder? [Ack. Looking into ~/Library/Preferences/com.apple.sidebars.plist, it isn't at all clear how I'd populate it.] Similar Questions: AppleScript: adding mounted folder to Finder Sidebar? suggests using fstab; this code will most likely run as a user and really, automounting at that point would be too late. How do you programmatically put folder icons on the Finder sidebar, given that you have to use a custom icon for the folder? Says there is no Cocoa API, but that you can use a carbon-style LSSharedFileList API that is only documented in a single header file. Does anyone know of some example code to add an item to the Finder sidebar?

    Read the article

  • Code Profiling in the Windows Sidebar Environment

    - by Matt
    Does anyone know of a way I can code-profile my Windows Sidebar Gadget? I've played around with the code-profiling tool in IE8's "Developer Tools" and the code-profiling included in Visual Studio 2010, but I can't find a way to include the System.* API, which my gadget relies on (as it is standard in the Sidebar environment). The gadget also relies on cross-domain AJAX requests; which is normally permitted in the Sidebar environment. By code-profiling I primarily mean: Function call count Function execution time Any ideas would be much appreciated. Regards, Matt

    Read the article

  • FF extension: displaying an array of string elements in a sidebar

    - by sujay-jain
    I am developing a ff extension which displays a list of elements from an array (dynamic) in the sidebar. The array is dynamic and needs to be constructed in a function everytime the sidebar is opened (or any other event handler). Later, i will need to implement link functionality on parts of the string. What is the best way to go about this? I have created an empty sidebar and just know the label element as of now. menu, and menuitem dont work. What other elements can i use to display text in a good way which supports dynamic contruction. Is there some good tutorial/sample extension which i can see and learn?

    Read the article

  • sidebar covers footer in internet explorer 6 and 7

    - by Datis
    i have designed a template for wordpress, the problem is that when sidebar gets longer some of it will cover the footer in internet explorer 6 and 7, the website address is : http://blog.baabak.ir (its in persian), but if you look at it in internet explorer 6,7 you will see the sidebar logo will cover the footer, for example in this page : http://blog.baabak.ir/?page%5Fid=141 but the website is ok in other browsers, whats the problem ?

    Read the article

  • css: problems with floating a sidebar

    - by user239831
    hey guys, i can't seem to get it working. i have a div.post with #comments and a #respond form underneath it. the div.post contains the #comments and the #respond form. i simply want to float the sidebar to the right of the entire div.post and i cannot seem to get it work. here is an example. any idea how to solve that - its probably quite simple. :) <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>layout</title> <style type="text/css"> body { margin:0; padding:0; } #main { width:100%; background:#cfcfcf; } .inner { margin: 0 auto; padding: 96px 72px 0; width: 1068px; border-color: #000; border-style: solid; border-width: 0 1px; color: #3C3C3C; } .post { width: 705px; background:#999; } #comments, #respond { width: 705px; background:#999; } #sidebar { width:338px; background:#777; margin-left:730px; } </style> </head> <body> <div id="main"> <div class="inner"> <div id="post" class="post"> <h2>Lorem Ipsum Test Page</h2> <div class="entry"> <p>Lorem ipsum sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p> <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p> </div> <!-- entry --> <div id="comments"> <h2>One Response</h2> <ol class="commentlist"> <li id="comment" class="comment"> <div class="comment-body"> <div class="comment-author vcard"> Tom says: </div> <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea found. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p> </div> </li> </ol> </div> <!-- comments --> <div id="respond"> <h2>Leave a Reply</h2> <form id="commentform" method="post" action=""> <input type="text" aria-required="true" tabindex="1" size="22" value="" id="author" name="author" gtbfieldid="230"> <label for="author">Name (required)</label> <input type="text" aria-required="true" tabindex="2" size="22" value="" id="email" name="email" gtbfieldid="231"> <label for="email">Mail (will not be published) (required)</label> <input type="text" tabindex="3" size="22" value="" id="url" name="url" gtbfieldid="232"> <label for="url">Website</label> </div> <textarea tabindex="4" rows="10" cols="58" id="comment" name="comment"></textarea> <input type="submit" value="Submit Comment" tabindex="5" id="submit" name="submit"> <input type="hidden" id="comment_post_ID" value="36" name="comment_post_ID"> <input type="hidden" value="0" id="comment_parent" name="comment_parent"> </form> </div> <!-- respond --> </div> <!-- post --> <div id="sidebar"> <h2>Meta</h2> <ul> <li>Login</li> <li>Anything</li> </ul> <h2>Subscribe</h2> <ul> <li>Entries (RSS)</li> <li>Comments (RSS)</li> </ul> </div> <!-- sidebar --> </div> <!-- inner --> </div> <!-- main --> </body> </html> edit: can you see any errors in my html. firebug says that the sidebar div is actually outside the .inner div. however if i look at the code it's inside.

    Read the article

  • I'm looking for Sidebar Menu Library for iOS

    - by Swordfish
    I'm looking for sidebar menu library similar to facebook. But sliding direction is opposite, not sliding left and right. What I need is up/down sliding way. I found many great soltutions for sidebar menu. But these things are usually that sliding directions is not what I need. These way is similar to taskbar of 6.0 ios Version. My app is for iPad, So, I want to use the bottom side of the screen. Weather + use this way. If anyone knows the solution to solve this, Please let me know it.

    Read the article

  • Manage Your Twitter Account from the Sidebar in Firefox

    - by Asian Angel
    Are you a Twitter addict and need an easy way to manage your account in Firefox? Now you can access Twitter in your Sidebar or as a separate window with the TwitKit+ extension for Firefox. Accessing TwitKit+ There are three ways that you can access TwitKit+ after installing the extension. The first is by adding the “Toolbar Button” to your browser’s UI. The second and third methods are through the “View & Tools Menus”.   TwitKit+ in Action When you open TwitKit+ for the first time you will see Twitter’s “Public Tweet Stream”. To get started login into your account. Note: If you do not care for the “brown theme” you can select a different one in “Preferences”. Here is a closer look at the top area and the commands available. Notice the “blue arrow symbol” in the upper left corner…very useful if you want to separate TwitKit+ from your main browser window for a bit. Secure Mode, Undock, Preferences, Login/Logout Google Search, Twitter Search, Copy Selection To Status Box, Shorten Selected URL Public, User, Friends, Followers, @ Messages, Direct Messages, Profile Note: To use Google or Twitter search enter your term in the “Status Area” and click on the appropriate service icon. Here is the regular timeline for our account…the “clickable tab buttons” make everything easy to view and work with. You can perform actions such as replying, retweeting, marking as a favorite, etc. using the set of “management buttons” at the bottom of each tweet. To add a new tweet to your timeline enter your text and press “Enter”. A look at the “Following List” for our account. Having a more defined and separate “view categories” set makes this better than directly accessing the Twitter website. Preferences The preferences can be quickly sorted out…choose how often the timeline is updated, name display, favorite URL shortening service, theme, and font size. Note: The default connection setting is for “Secure Access”. Conclusion TwitKit+ makes a nice addition to Firefox for anyone who loves keeping up with Twitter throughout the day. There when you want it and out of your way the rest of the time. Links Download the TwitKit+ extension (Mozilla Add-ons) Similar Articles Productive Geek Tips Move Add-on Management to the Sidebar in FirefoxPreview and Manage Multiple Tabs in Firefox with Tab SidebarDisable Windows Sidebar in VistaQuick Tip: Use Google Talk Sidebar in FirefoxRun Windows Sidebar Gadgets Without the Sidebar TouchFreeze Alternative in AutoHotkey The Icy Undertow Desktop Windows Home Server – Backup to LAN The Clear & Clean Desktop Use This Bookmarklet to Easily Get Albums Use AutoHotkey to Assign a Hotkey to a Specific Window Latest Software Reviews Tinyhacker Random Tips Revo Uninstaller Pro Registry Mechanic 9 for Windows PC Tools Internet Security Suite 2010 PCmover Professional Enable Check Box Selection in Windows 7 OnlineOCR – Free OCR Service Betting on the Blind Side, a Vanity Fair article 30 Minimal Logo Designs that Say More with Less LEGO Digital Designer – Free Create a Personal Website Quickly using Flavors.me

    Read the article

  • Manage Your Twitter Account from the Sidebar in Firefox

    - by Asian Angel
    Are you a Twitter addict and need an easy way to manage your account in Firefox? Now you can access Twitter in your Sidebar or as a separate window with the TwitKit+ extension for Firefox. Accessing TwitKit+ There are three ways that you can access TwitKit+ after installing the extension. The first is by adding the “Toolbar Button” to your browser’s UI. The second and third methods are through the “View & Tools Menus”.   TwitKit+ in Action When you open TwitKit+ for the first time you will see Twitter’s “Public Tweet Stream”. To get started login into your account. Note: If you do not care for the “brown theme” you can select a different one in “Preferences”. Here is a closer look at the top area and the commands available. Notice the “blue arrow symbol” in the upper left corner…very useful if you want to separate TwitKit+ from your main browser window for a bit. Secure Mode, Undock, Preferences, Login/Logout Google Search, Twitter Search, Copy Selection To Status Box, Shorten Selected URL Public, User, Friends, Followers, @ Messages, Direct Messages, Profile Note: To use Google or Twitter search enter your term in the “Status Area” and click on the appropriate service icon. Here is the regular timeline for our account…the “clickable tab buttons” make everything easy to view and work with. You can perform actions such as replying, retweeting, marking as a favorite, etc. using the set of “management buttons” at the bottom of each tweet. To add a new tweet to your timeline enter your text and press “Enter”. A look at the “Following List” for our account. Having a more defined and separate “view categories” set makes this better than directly accessing the Twitter website. Preferences The preferences can be quickly sorted out…choose how often the timeline is updated, name display, favorite URL shortening service, theme, and font size. Note: The default connection setting is for “Secure Access”. Conclusion TwitKit+ makes a nice addition to Firefox for anyone who loves keeping up with Twitter throughout the day. There when you want it and out of your way the rest of the time. Links Download the TwitKit+ extension (Mozilla Add-ons) Similar Articles Productive Geek Tips Move Add-on Management to the Sidebar in FirefoxPreview and Manage Multiple Tabs in Firefox with Tab SidebarDisable Windows Sidebar in VistaQuick Tip: Use Google Talk Sidebar in FirefoxRun Windows Sidebar Gadgets Without the Sidebar TouchFreeze Alternative in AutoHotkey The Icy Undertow Desktop Windows Home Server – Backup to LAN The Clear & Clean Desktop Use This Bookmarklet to Easily Get Albums Use AutoHotkey to Assign a Hotkey to a Specific Window Latest Software Reviews Tinyhacker Random Tips Revo Uninstaller Pro Registry Mechanic 9 for Windows PC Tools Internet Security Suite 2010 PCmover Professional Enable Check Box Selection in Windows 7 OnlineOCR – Free OCR Service Betting on the Blind Side, a Vanity Fair article 30 Minimal Logo Designs that Say More with Less LEGO Digital Designer – Free Create a Personal Website Quickly using Flavors.me

    Read the article

  • JQuery - Sticky sidebar not working in Firefox

    - by user1473358
    I'm working on a site with a Sticky sidebar (fixed position under certain conditions, etc) that is working fine in Chrome & Safari, but breaks in Firefox. I'm not sure what the issue is since I didn't write the script: $(document).ready(function() { /* var defaults = { containerID: 'toTop', // fading element id containerHoverID: 'toTopHover', // fading element hover id scrollSpeed: 1200, easingType: 'linear' }; */ $().UItoTop({ easingType: 'easeOutQuart' }); if (!!$('.sticky').offset()) { // make sure ".sticky" element exists var stickyTop = $('.sticky').offset().top; // returns number var newsTop = $('#news_single').offset().top; // returns number $(window).scroll(function(){ // scroll event var windowTop = $(window).scrollTop(); // returns number var width = $(window).width(); var height = $(window).height(); if (stickyTop < windowTop && width > 960 && height > 450){ $('.sticky').css({ position: 'fixed', top: 40 }); $('#news_single').css({ left: 230 }); } else { $('.sticky').css('position','static'); $('#news_single').css({ left: 0 }); } }); } }); Here's the site (the sidebar in question is the one with the red header, to the left): http://www.parisgaa.org/parisgaels/this-is-a-heading-too-a-longer-one I'd appreciate any help with this.

    Read the article

  • Windows Sidebar gadget not working in vista home premium(ie 64-bit OS)

    - by stanley
    Hi All, I have developed a windows sidebar gadget which plays videos in a flash player, It works in vista home basic(32-bit OS) but doesn't work in vista home premium(64-bit OS). I use Flash Player 9 and Actionscript 3.0. Can anyone help me Please. ***This is the html content for the player*** <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="130" height="200" id="FLVPlayer"> <param name="movie" value="test.swf" /> <param name="salign" value="lt" /> <param name="quality" value="high" /> <param name="scale" value="noscale" /> <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=2973&autoPlay=true&autoRewind=true" /> <embed src="test.swf" flashvars="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=2973&autoPlay=true&autoRewind=true" quality="high" scale="noscale" width="130" height="200" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" />

    Read the article

  • Wordpress sidebar classes

    - by Chris J. Lee
    There any way i could add a class for the specific order of widget item? i.e. the class name would be widgetorder-1 (for the first appearing widget), widgetorder-2 (for the widget appearing in the 2nd order), etc. I looked into filters but wasn't sure how that worked.

    Read the article

  • Give permissions for packages downloaded from the internet and lock them in Ubuntu 12.04 sidebar

    - by JuninhoDG
    I downloaded NetBeans IDE and Eclipse IDE from the internet and installed then. Well, the Eclipse IDE works fine, but when I execute NetBeans IDE directly from the link, without sudo permission, it shows me lots of error telling that some files are read only. This does not happens when I'm using the terminal to call the .sh script with sudo permissions. Another thing that bothers me: How can I fix my shortcuts in the Ubuntu's 12.04 sidebar? I want to combine a launcher with enough permissions to do everything it's needing and fix it in my sidebar. Is it possible?

    Read the article

  • firefox sidebar menu or list of elements. resources/help

    - by sujay-jain
    I am struggling to find any resources on firefox extensions which construct a sidebar and put elements into them. plus tyhe other functionalities within a sidebar. I have made a emptysidebar. Now i need to display a dynamic array(which is formed using a JS function). I have absolutely no idea how to go about it. Can someone please help! this is the code of the sidebar page. I need a xul element like the menuitem where i can display a list of items. How do i get that in a sidebar? <page id="sbEmptySidebar" title="emptysidebar" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" > <vbox flex="1"> <label id ="l1"> </vbox> </page>

    Read the article

  • ASP.NET MVC 3: Layouts and Sections with Razor

    - by ScottGu
    This is another in a series of posts I’m doing that cover some of the new ASP.NET MVC 3 features: Introducing Razor (July 2nd) New @model keyword in Razor (Oct 19th) Layouts with Razor (Oct 22nd) Server-Side Comments with Razor (Nov 12th) Razor’s @: and <text> syntax (Dec 15th) Implicit and Explicit code nuggets with Razor (Dec 16th) Layouts and Sections with Razor (Today) In today’s post I’m going to go into more details about how Layout pages work with Razor.  In particular, I’m going to cover how you can have multiple, non-contiguous, replaceable “sections” within a layout file – and enable views based on layouts to optionally “fill in” these different sections at runtime.  The Razor syntax for doing this is clean and concise. I’ll also show how you can dynamically check at runtime whether a particular layout section has been defined, and how you can provide alternate content (or even an alternate layout) in the event that a section isn’t specified within a view template.  This provides a powerful and easy way to customize the UI of your site and make it clean and DRY from an implementation perspective. What are Layouts? You typically want to maintain a consistent look and feel across all of the pages within your web-site/application.  ASP.NET 2.0 introduced the concept of “master pages” which helps enable this when using .aspx based pages or templates.  Razor also supports this concept with a feature called “layouts” – which allow you to define a common site template, and then inherit its look and feel across all the views/pages on your site. I previously discussed the basics of how layout files work with Razor in my ASP.NET MVC 3: Layouts with Razor blog post.  Today’s post will go deeper and discuss how you can define multiple, non-contiguous, replaceable regions within a layout file that you can then optionally “fill in” at runtime. Site Layout Scenario Let’s look at how we can implement a common site layout scenario with ASP.NET MVC 3 and Razor.  Specifically, we’ll implement some site UI where we have a common header and footer on all of our pages.  We’ll also add a “sidebar” section to the right of our common site layout.  On some pages we’ll customize the SideBar to contain content specific to the page it is included on: And on other pages (that do not have custom sidebar content) we will fall back and provide some “default content” to the sidebar: We’ll use ASP.NET MVC 3 and Razor to enable this customization in a nice, clean way.  Below are some step-by-step tutorial instructions on how to build the above site with ASP.NET MVC 3 and Razor. Part 1: Create a New Project with a Layout for the “Body” section We’ll begin by using the “File->New Project” menu command within Visual Studio to create a new ASP.NET MVC 3 Project.  We’ll create the new project using the “Empty” template option: This will create a new project that has no default controllers in it: Creating a HomeController We will then right-click on the “Controllers” folder of our newly created project and choose the “Add->Controller” context menu command.  This will bring up the “Add Controller” dialog: We’ll name the new controller we create “HomeController”.  When we click the “Add” button Visual Studio will add a HomeController class to our project with a default “Index” action method that returns a view: We won’t need to write any Controller logic to implement this sample – so we’ll leave the default code as-is.  Creating a View Template Our next step will be to implement the view template associated with the HomeController’s Index action method.  To implement the view template, we will right-click within the “HomeController.Index()” method and select the “Add View” command to create a view template for our home page: This will bring up the “Add View” dialog within Visual Studio.  We do not need to change any of the default settings within the above dialog (the name of the template was auto-populated to Index because we invoked the “Add View” context menu command within the Index method).  When we click the “Add” Button within the dialog, a Razor-based “Index.cshtml” view template will be added to the \Views\Home\ folder within our project.  Let’s add some simple default static content to it: Notice above how we don’t have an <html> or <body> section defined within our view template.  This is because we are going to rely on a layout template to supply these elements and use it to define the common site layout and structure for our site (ensuring that it is consistent across all pages and URLs within the site).  Customizing our Layout File Let’s open and customize the default “_Layout.cshtml” file that was automatically added to the \Views\Shared folder when we created our new project: The default layout file (shown above) is pretty basic and simply outputs a title (if specified in either the Controller or the View template) and adds links to a stylesheet and jQuery.  The call to “RenderBody()” indicates where the main body content of our Index.cshtml file will merged into the output sent back to the browser. Let’s modify the Layout template to add a common header, footer and sidebar to the site: We’ll then edit the “Site.css” file within the \Content folder of our project and add 4 CSS rules to it: And now when we run the project and browse to the home “/” URL of our project we’ll see a page like below: Notice how the content of the HomeController’s Index view template and the site’s Shared Layout template have been merged together into a single HTML response.  Below is what the HTML sent back from the server looks like: Part 2: Adding a “SideBar” Section Our site so far has a layout template that has only one “section” in it – what we call the main “body” section of the response.  Razor also supports the ability to add additional "named sections” to layout templates as well.  These sections can be defined anywhere in the layout file (including within the <head> section of the HTML), and allow you to output dynamic content to multiple, non-contiguous, regions of the final response. Defining the “SideBar” section in our Layout Let’s update our Layout template to define an additional “SideBar” section of content that will be rendered within the <div id=”sidebar”> region of our HTML.  We can do this by calling the RenderSection(string sectionName, bool required) helper method within our Layout.cshtml file like below:   The first parameter to the “RenderSection()” helper method specifies the name of the section we want to render at that location in the layout template.  The second parameter is optional, and allows us to define whether the section we are rendering is required or not.  If a section is “required”, then Razor will throw an error at runtime if that section is not implemented within a view template that is based on the layout file (which can make it easier to track down content errors).  If a section is not required, then its presence within a view template is optional, and the above RenderSection() code will render nothing at runtime if it isn’t defined. Now that we’ve made the above change to our layout file, let’s hit refresh in our browser and see what our Home page now looks like: Notice how we currently have no content within our SideBar <div> – that is because the Index.cshtml view template doesn’t implement our new “SideBar” section yet. Implementing the “SideBar” Section in our View Template Let’s change our home-page so that it has a SideBar section that outputs some custom content.  We can do that by opening up the Index.cshtml view template, and by adding a new “SiderBar” section to it.  We’ll do this using Razor’s @section SectionName { } syntax: We could have put our SideBar @section declaration anywhere within the view template.  I think it looks cleaner when defined at the top or bottom of the file – but that is simply personal preference.  You can include any content or code you want within @section declarations.  Notice above how I have a C# code nugget that outputs the current time at the bottom of the SideBar section.  I could have also written code that used ASP.NET MVC’s HTML/AJAX helper methods and/or accessed any strongly-typed model objects passed to the Index.cshtml view template. Now that we’ve made the above template changes, when we hit refresh in our browser again we’ll see that our SideBar content – that is specific to the Home Page of our site – is now included in the page response sent back from the server: The SideBar section content has been merged into the proper location of the HTML response : Part 3: Conditionally Detecting if a Layout Section Has Been Implemented Razor provides the ability for you to conditionally check (from within a layout file) whether a section has been defined within a view template, and enables you to output an alternative response in the event that the section has not been defined.  This provides a convenient way to specify default UI for optional layout sections.  Let’s modify our Layout file to take advantage of this capability.  Below we are conditionally checking whether the “SideBar” section has been defined without the view template being rendered (using the IsSectionDefined() method), and if so we render the section.  If the section has not been defined, then we now instead render some default content for the SideBar:  Note: You want to make sure you prefix calls to the RenderSection() helper method with a @ character – which will tell Razor to execute the HelperResult it returns and merge in the section content in the appropriate place of the output.  Notice how we wrote @RenderSection(“SideBar”) above instead of just RenderSection(“SideBar”).  Otherwise you’ll get an error. Above we are simply rendering an inline static string (<p>Default SideBar Content</p>) if the section is not defined.  A real-world site would more likely refactor this default content to be stored within a separate partial template (which we’d render using the Html.RenderPartial() helper method within the else block) or alternatively use the Html.Action() helper method within the else block to encapsulate both the logic and rendering of the default sidebar. When we hit refresh on our home-page, we will still see the same custom SideBar content we had before.  This is because we implemented the SideBar section within our Index.cshtml view template (and so our Layout rendered it): Let’s now implement a “/Home/About” URL for our site by adding a new “About” action method to our HomeController: The About() action method above simply renders a view back to the client when invoked.  We can implement the corresponding view template for this action by right-clicking within the “About()” method and using the “Add View” menu command (like before) to create a new About.cshtml view template.  We’ll implement the About.cshtml view template like below. Notice that we are not defining a “SideBar” section within it: When we browse the /Home/About URL we’ll see the content we supplied above in the main body section of our response, and the default SideBar content will rendered: The layout file determined at runtime that a custom SideBar section wasn’t present in the About.cshtml view template, and instead rendered the default sidebar content. One Last Tweak… Let’s suppose that at a later point we decide that instead of rendering default side-bar content, we just want to hide the side-bar entirely from pages that don’t have any custom sidebar content defined.  We could implement this change simply by making a small modification to our layout so that the sidebar content (and its surrounding HTML chrome) is only rendered if the SideBar section is defined.  The code to do this is below: Razor is flexible enough so that we can make changes like this and not have to modify any of our view templates (nor make change any Controller logic changes) to accommodate this.  We can instead make just this one modification to our Layout file and the rest happens cleanly.  This type of flexibility makes Razor incredibly powerful and productive. Summary Razor’s layout capability enables you to define a common site template, and then inherit its look and feel across all the views/pages on your site. Razor enables you to define multiple, non-contiguous, “sections” within layout templates that can be “filled-in” by view templates.  The @section {} syntax for doing this is clean and concise.  Razor also supports the ability to dynamically check at runtime whether a particular section has been defined, and to provide alternate content (or even an alternate layout) in the event that it isn’t specified.  This provides a powerful and easy way to customize the UI of your site - and make it clean and DRY from an implementation perspective. Hope this helps, Scott P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >