<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecore Xperiences &#187; Architecture</title>
	<atom:link href="https://blog.peplau.com.br/tag/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.peplau.com.br</link>
	<description>The things I&#039;ve seen as a Sitecore Professional</description>
	<lastBuildDate>Sun, 09 Mar 2025 21:54:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>How would you do it: 2 levels menu</title>
		<link>https://blog.peplau.com.br/how-would-you-do-2-levels-menu/</link>
		<comments>https://blog.peplau.com.br/how-would-you-do-2-levels-menu/#comments</comments>
		<pubDate>Mon, 09 Feb 2015 20:24:17 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=57</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/how-would-you-do-2-levels-menu/"></div>One of our clients has a development team that will take over the project as soon as we finish our part. They have great developers with no Sitecore experience, and some of their questions are pretty valuable for those starting in the Sitecore world. My answer that follows has a consultancy approach, providing explanations and advises at a higher level. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One of our clients has a development team that will take over the project as soon as we finish our part. They have great developers with no Sitecore experience, and some of their questions are pretty valuable for those starting in the Sitecore world. My answer that follows has a consultancy approach, providing explanations and advises at a higher level.</p>
<p>Here is the question:</p>
<blockquote><p>In Sitecore, how would you organize architecture and static files &#8211; mainly CSS and javascript files &#8211; during development of the following two levels menu?</p>
<p>The first level shows an Image and a Title and starts closed:<br />
<a href="http://blog.peplau.com.br/wp-content/uploads/Menu2l-closed.png"><img class=" wp-image-58 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Menu2l-closed.png" alt="Menu2l - closed" width="600" height="140" /></a></p>
<p>When the user hovers a block at Level 1, a second part is displayed showing items on Level 2:<a href="http://blog.peplau.com.br/wp-content/uploads/Menu2l-hover1.png"><img class=" wp-image-64 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Menu2l-hover1.png" alt="Menu2l - hover" width="600" height="421" /></a></p></blockquote>
<p><strong>Answer</strong></p>
<p>Your static CSS and Javascript files, like in any other web application, must be loaded somehow. At the project we are working, we have a <a href="https://msdn.microsoft.com/en-us/magazine/dn451436.aspx" target="_blank">bundle and minification</a> process in place, responsible for loading, minify&#8217;ing and caching the files so everything loads faster.</p>
<p>But you can load files the old way:</p>
<blockquote>
<pre>&lt;script src="myscript.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
</blockquote>
<p>The implementation itself can be split into two different challenges:</p>
<ol>
<li><strong>Front-end development</strong><br />
We clearly have a good front-end work here, some dynamic behavior when user hovers around level 1, the look and feel and everything. Basically all HTML markup, javascript and css stylesheets can be prepared without having Sitecore specifically in mind;</li>
<li><strong>Back end development</strong><br />
All necessary to enable the content edition of menu items, and make it work dynamically at a page, including:</p>
<ul>
<li><strong>Step 1 -</strong> Upload your javascript and CSS files somewhere at your site filesystem (Eg: &#8220;<em>/assets/js</em>&#8221; and &#8220;<em>/assets/css</em>&#8220;), then load them somehow (traditional, bundle, etc);</li>
<li><strong>Step 2 -</strong> Define your data structure (templates and fields) to support the content management. It all depends on your requirements &#8211; let&#8217;s have the following two possible scenarios:
<ul>
<li><strong>Scenario 1 -</strong> You may want to feed the menu with pages and subpages you already have in your content tree. In this case you would just use your existing data:<br />
<a href="http://blog.peplau.com.br/wp-content/uploads/Menu-Tree.png"><img class=" size-full wp-image-68 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Menu-Tree.png" alt="Menu Tree" width="159" height="139" /></a></li>
<li><strong>Scenario 2 -</strong> Or you may be asked to create a dedicated data structure, not pages themselves but pointing to real pages. This data structure would have the following format:<br />
<strong>Menu Item Level 1</strong><br />
<a href="http://blog.peplau.com.br/wp-content/uploads/Sitecore-Template-Menu-Level-11.png"><img class="alignnone  wp-image-71" src="http://blog.peplau.com.br/wp-content/uploads/Sitecore-Template-Menu-Level-11.png" alt="Sitecore Template Menu Level 1" width="462" height="106" /></a><strong>Menu Item Level 2</strong><br />
<a href="http://blog.peplau.com.br/wp-content/uploads/Sitecore-Template-Menu-Level-21.png"><img class="alignnone  wp-image-72" src="http://blog.peplau.com.br/wp-content/uploads/Sitecore-Template-Menu-Level-21.png" alt="Sitecore Template Menu Level 2" width="463" height="130" /></a>And you would keep the item somewhere outside your page&#8217;s content tree:<br />
<a href="http://blog.peplau.com.br/wp-content/uploads/Menu-Tree-2.png"><img class="alignnone size-full wp-image-74" src="http://blog.peplau.com.br/wp-content/uploads/Menu-Tree-2.png" alt="Menu Tree 2" width="164" height="141" /></a></li>
</ul>
</li>
<li><strong>Step 3 -</strong> Create the component/sublayout that implements the menu feature. Following the same two scenarios above:
<ul>
<li><strong>Scenario 1 -</strong> In this case you would use the Sitecore API to pragmatically get the Home item, using Children items to render menu&#8217;s level 1, and their grandchildren rendering level 2:
<pre>var homeItem = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
var levelOne = homeItem.Children.ToList();
foreach (var itemLevelOne in levelOne) {
   // This item represents a Level 1 menu block
   var title = itemLevelOne.Fields["Title"].Value;
   var image = itemLevelOne.Fields["Image"].Value;
   var levelTwo = itemLevelOne.Children.ToList();
   // ... do whatever you need with Level 1
   foreach (var itemLevelTwo in levelTwo) {
      // Here you work your Level 2 item
      var titleLevelTwo = itemLevelTwo.Fields["Title"].Value;
   }
}</pre>
</li>
<li><strong>Scenario 2 -</strong> This implementation would be very similar to the first scenario, except that you would have to start at your repository folder (Eg: <em>/sitecore/content/Lists/Menu</em>) instead of the Home item.</li>
</ul>
</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/how-would-you-do-2-levels-menu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
