Showing posts with label Sitecore Marketplace. Show all posts
Showing posts with label Sitecore Marketplace. Show all posts

Saturday, June 29, 2013

Sitecore How-To: Sitecore Country and Region Dropdowns

We had a couple people in the Guild ask about country and region DropDownLists so thought Dennis Augustine and I thought we would write an article on it.  

Problem: In our application we require a country and region picker.  When someone chooses a company we need to filter the region picker.

Solution: This can be accomplished by adding two DropDownList controls to your SubLayout. Call one ddlCountry and the other ddlRegion.  

In the content tree under a shared lookup area create a folder called "Country"  under this folder add the countries with key as country code and phrase as country name.  Next under each country create a folder called "Regions" store all the regions in this folder.  I use DictionaryEntry as my Sitecore Data Template for the country and regions.

On Page_load you would call GetCountries() and assign it to the ddlCountries.DataSource Property.

    protected override void OnLoad(EventArgs e)
    {
       ddlCountry.DataSource = GetCountries(); 
       ddlCountry.DataValueField = "Key"; 
       ddlCountry.DataTextField = "Phrase"; 
       ddlCountry.DataBind(); 
   }

Next trap the change in country using the following event:

protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
            ddlRegion.DataSource = GetRegions(ddlCountry.SelectedValue); 
            ddlRegion.DataValueField = "Key"; 
            ddlRegion.DataTextField = "Phrase";  
           ddlRegion.DataBind(); 
    }

Next add the following code to the sublayout. Ideally later you would store these in a library for use late in other parts of your code. Also note that you would need to change "SiteSettings.LookupPath" to the path where you are storing your countries in the tree.  This setting occurs a couple times in my code below.

///<summary> 
/// Getting children items by parent item path 
///</summary> 
/// <param name="itemPath"></param> 
/// <returns>List<LookupItem></returns> 
public static List<LookupItem> GetLookupItemChildren(string itemPath) 

Item item = Sitecore.Context.Database.Items[itemPath]; 
List<LookupItem> lst = new List<LookupItem>(); 

if (item != null) 

foreach (Item child in item.Children) 

lst.Add( new LookupItem(child["Key"], child["Phrase"],child["AlternatePhrase"])); 



return lst; 


///<summary> 
/// Getting Countries by Countries 
///</summary> 
public static List<LookupItem> GetCountries() 

return Lookups.GetLookupItemChildren(SiteSettings.LookupsPath + "/Country"); 


///<summary> 
/// Getting Regions By Country KEY 
///</summary> 
public static List<LookupItem> GetRegions(string countryKey) 

Item item = Lookups.GetItemByKey(SiteSettings.LookupsPath + "/Country", countryKey);
return Lookups.GetLookupItemChildren(SiteSettings.LookupsPath + "/Country/" + item.Name + "/Regions"); 


In Sitecore 7 you can replace these item lookups with LINQ statement.

Dennis Augustine has now created and uploaded the Country Region Dropdown Sitecore Module based on the blog post and it is now available in the Sitecore MarketPlace as a Development Accelerator.

If you have any questions or any tips, tricks or resources you would like to share with the Guild please email me at chris.williams@threepointturn.com or dennis.augustine@threepointturn.com 

Wednesday, November 24, 2010

Sitecore - Getting Started Tips

Last night was the Toronto Sitecore Users Group meeting and I noticed there are were a lot of people just starting out with Sitecore. I figured it would he helpful if our first Sitecore Guild blog post assisted some of those beginners. If you have any additional tips for beginners feel free to comment on this post.

1) Take the Sitecore Training. If you have not been trained
on Sitecore, you will miss a lot of key concepts that will
hinder the success of your project. I know from experience.

2) Set up Sitecore to support multiple domains at the start.This will help you later when you want another site to share content.

Planning for shared content across sites will force you into the mindset
of shared content and code. This will help you on future projects too.

NOTE: In newer versions of Sitecore use an app.config file for each site to store the site mapping and other site specific settings. This will simplify upgrading.

Configuring Multiple Sites / Configuring Sites in web.config File

Read Watch Create has developed a free MultisiteQuickStart. If interested email chris.williams@readwatchcreate.com


3) Remember not all data needs to be in the CMS. Sometimes
data such as billing information do not need version control
or publishing rules. It is better to leave these items in
the database where they belong.

4) Wildcard content items are your best friend.
You may run into situations where you have content that is not in the content tree but you still want friendly urls not query strings.
It may not live in the CMS either because of tip 2 or because the data is coming from an external source

The solution is to place a * node below a node to accept all urls below it. Then instead of parsing a query string you would parse an url
for the data.

Here is the link and a brief note on wildcard nodes:

Sitecore Avoiding Query String In Dynamic Url

5) Resource Strings are content.
Store all your static string in the Content Tree as ResourceStrings.
This is a shift from standard .net where your resource strings would be
compiled in a resource file. By doing this, resource strings can be changed
by a content editor. Additional languages, in most cases would not require a recompile.

UPDATE: Check out this blog post for more information on the Resource String Module in the Sitecore MarketPlace

6) Keep common functionality together.
In the database, layouts, sublayouts, renderings exist in different nodes in the site but
In the physical folders, if you keep all the items related to a given folder you can more easily
package them up for another project. You never know when you can reuse a component.

I set up my physical folders as follows:

components\classes
components\dataproviders
components\Layouts
components\SubLayouts
components\Renderings
components\webcontrols
components\{modulename}\classes
components\{modulename}\dataproviders
components\{modulename}\Layouts
components\{modulename}\SubLayouts
components\{modulename}\Renderings
components\{modulename}\webcontrols
{sitename}\\classes
{sitename}\\dataproviders
{sitename}\\Layouts
{sitename}\\SubLayouts
{sitename}\\Renderings
{sitename}\\webcontrols

This keeps all the general items together, the module specific and the site specific in their proper places.

7) Find it before trying to build it.
Sitecore developer love to share. Through trac and the Developer Network you will find a wealth of shared source you can simply use.

UPDATE: Sitecore MarketPlace provides a vast amount of modules and developer starting points to help you get started on development rather than starting form scratch.

You can also find cookbooks that will tell you step by step how to accomplish common tasks. Unless you are implementing
something really specific, you are likely to find
a solution with source code that will either solve your exact problem or at least are a good starting point.

http://sdn.sitecore.net

8) Get Help from others.
If you are doing your first Sitecore project, don't be afraid to partner up with someone who has already done one. Sitecore gives you the illusion that it is easy to start a site but there is an initial learning curve. A partner that has been through even a single project could
help you avoid common pitfalls that could save you lots of time on your project.

9) Pay it forward.
When working on your solutions, if you do have to write a custom module but feel its generic enough to help other developers later. Share it.
The more we share the stronger Sitecore gets and the more productive we get as a community.

10) Connect with other Sitecore Developers.
A good way to do this is through going to the User Group Meetings, joining the Sitecore Facebook Groups and connecting to each other
on various Social Networks to share.

11) Check out the Sitecore QuickStart Blog Series
I have recently started a blog series called Sitecore QuickStarts.  This series provides a step-by-step guide through setting up your Sitecore development environment, your Sitecore Instance and guide you on your way to a successful implementation.

Twitter is underrated as a knowledge base. The Toronto Sharepoint Users Group developed the concept of placing @TSPUG on posts. Instead of posting where they were, they posted a quick comment or question and a link to answers.

I have started up a twitter account for the Sitecore Guild at https://twitter.com/SitecoreGuild
Please connect on twitter and when you find cool things for sitecore post them and be sure to include @SitecoreGuild in the post so we can all find them.

I will be collecting some of them regularly and sharing them here with the guild as well.

If you have any tips, tricks or resources please share them on twitter, comment on a post here or email them to me at chris.williams@readwatchcreate.com