<?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>SkyBlueCanvas&#187; Converting Themes for SkyBlueCanvas &#8211; SkyBlueCanvas</title>
	<atom:link href="http://blog.skybluecanvas.com/tag/fragments/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.skybluecanvas.com</link>
	<description>The Lightweight Blog</description>
	<lastBuildDate>Tue, 20 Jul 2010 15:47:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Converting Themes for SkyBlueCanvas</title>
		<link>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/converting-themes-skybluecanvas/</link>
		<comments>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/converting-themes-skybluecanvas/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 20:14:19 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Skins and Templates]]></category>
		<category><![CDATA[SkyBlueCanvas CMS]]></category>
		<category><![CDATA[fragment]]></category>
		<category><![CDATA[fragments]]></category>
		<category><![CDATA[skin]]></category>
		<category><![CDATA[skins]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tutorials]]></category>
<category>conversion</category><category>fragments</category><category>html</category><category>skins</category><category>templates</category><category>themes</category>
		<guid isPermaLink="false">http://blog.skybluecanvas.com/?p=55</guid>
		<description><![CDATA[One of the most common questions we are asked is how to convert existing or stock HTML templates to work with 
SkyBlueCanvas. In this article I will guide you, step-by-step, through the process of adapting 
any existing skin to work with SkyBlueCanvas. This process, once you understand the fundamentals, 
usually takes about an hour - sometimes even less. In fact, the skin we will use in this tutorial 
took only 30 minutes.]]></description>
			<content:encoded><![CDATA[<p>One of the most common questions we are asked is how to convert existing or stock HTML templates to work with SkyBlueCanvas. In this article I will guide you, step-by-step, through the process of adapting any existing skin to work with SkyBlueCanvas. This process, once you understand the fundamentals, usually takes about an hour &#8211; sometimes even less. In fact, the skin we will use in this tutorial took only 30 minutes.</p>
<p>For this demonstration I will be using the Eco Theme from ThemeForest.net. Since this is a copyrighted theme, I won&#8217;t be able to give you the code for download, but you can purchase the template for only $12 from <a rel="nofollow" href="http://themeforest.net/item/eco-theme/22099?ref=skybluecanvas">ThemeForest.net</a>. I selected this theme because it&#8217;s beautiful, and it has all of the elements we need to learn how to adapt just about any skin for SkyBlueCanvas.</p>
<p><img style="padding: 1px; border: 1px solid #CCC; margin-bottom: 8px;" src="http://blog.skybluecanvas.com/images/eco.jpg" alt="Eco theme screen shot" width="200" height="150" /></p>
<p>The Eco Theme from <a rel="nofollow" href="http://themeforest.net/item/eco-theme/22099?ref=skybluecanvas">ThemeForest.net</a></p>
<h2>The Basics</h2>
<p>Since all of the HTML, CSS and JavaScript code has already been written by the theme author, our task will involve:</p>
<ul>
<li>Replacing content blocks with SkyBlueCanvas fragments</li>
<li>Replacing hard-coded page links with SkyBlueCanvas links</li>
<li>Updating CSS and JavaScript links for SkyBlueCanvas</li>
</ul>
<div class="msg-info">
<h2>Tip</h2>
<p>If you have not read our articles on <a href="http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-v11-rc1-skins-explained/">SkyBlueCanvas Skins</a> and <a href="http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-fragments-explained/">SkyBlueCanvas Fragments</a>, you may want to do so to get a full understanding of how SkyBlueCanvas creates a page.</p>
</div>
<p>Before we start, we need to create our skin directory structure. Create a new directory named eco with the following sub-folders:</p>
<p><img class="diagram" src="http://blog.skybluecanvas.com/images/diagram.skin.structure.jpg" alt="SkyBlueCanvas Skin directory structure" width="464" height="199" /></p>
<p>Next, copy the <span class="file-name">index.html</span> file from the Eco Theme to your new eco directory and rename it to <span class="file-name">skin.default.html</span>. Now copy the new eco directory to <span class="file-path">/skyblue/data/skins/</span>. Be sure to change the file permissions as needed for your hosting environment.</p>
<p>First, we need to add our links to the CSS and JavaScript files. Let&#8217;s take a look at the HTML HEAD element:</p>
<pre class="html">&lt;head&gt;
&lt;meta http-equiv="Content-Type"
  content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;The Eco Company Site Template&lt;/title&gt;
&lt;link rel="stylesheet"
  href="css/style.css"
  type="text/css"
  media="screen" /&gt;
&lt;script src="js/jquery-1.2.6.js"
  type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="js/jquery.scrollTo-1.3.3.js"
  type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="js/jquery.localscroll-1.2.5.js"
  type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="js/jquery.serialScroll-1.2.1.js"
  type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="js/coda-slider.js"
type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
</pre>
<p>You will notice that the paths for the CSS and JavaScript files all point to the relative paths within the skin directory. These won&#8217;t work from the front-end of your site but they are easily updated. I will just show you how to update one JavaScript and one CSS link. The others will be done the same way.</p>
<p>You will need one simple bit of PHP code to get the path to the currently active skin in SkyBlueCanvas:</p>
<pre class="php">&lt;?php echo $this-&gt;get_path(); ?&gt;
</pre>
<p>So we just need to add this code before the existing paths in the Eco Theme code:</p>
<pre class="html">&lt;head&gt;
&lt;link rel="stylesheet"
  href="&lt;?php echo $this-&gt;get_path(); ?&gt;css/style.css"
  type="text/css" media="screen" /&gt;
&lt;script src="&lt;?php echo $this-&gt;get_path(); ?&gt;js/jquery-1.2.6.js"
  type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
</pre>
<p>Next, let&#8217;s tackle the header. This will be very easy. I will give you the code, then explain it.</p>
<pre class="html">&lt;div id="logo"&gt;
  &lt;h1&gt;&lt;a href="[[site.url]]"&gt;
    &lt;img src="images/logo.gif" alt="[[site.name]] logo" /&gt;
  &lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
</pre>
<p>That&#8217;s it. All we have done is replaced the hard-coded URL of the home page and the site name with two SiteVars. Now, when our page is rendered, SkyBlueCanvas will replace these with the values you set in the SkyBlueCanvas admin.</p>
<div class="msg-info">
<h2>Tip</h2>
<p>You can find a full list of SiteVars in our article about the<br />
<a href="http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-sitevars-plugin/">SkyBlueCanvas SiteVars Plugin</a>.</p>
</div>
<p>Now we will do the same for the Contacts region of the header:</p>
<pre class="html">&lt;div id="contacts"&gt;
  &lt;!-- Contact informations here --&gt;
  &lt;p&gt;
    Call us at [[site.contact_phone]] &lt;br /&gt;
    &lt;a href="mailto:[[site.contact_email]]"&gt;
      [[site.contact_email]]
    &lt;/a&gt;
  &lt;/p&gt;
  &lt;!-- End of Contact informations --&gt;
&lt;/div&gt;
</pre>
<p>Next, let&#8217;s replace the hard-coded dynamic content blocks. Converting content blocks involves two SkyBlueCanvas concepts: Fragments and SiteVars (which we already mentioned). Fragments are scriptlets that render a particular kind of content &#8211; like a Links List &#8211; created by SkyBlueCanvas. SiteVars are tokens that refer to settings or values that you set in the SkyBlueCanvas admin. They allow you to change values related to your site, without having to change your HTML every time you update your site settings.</p>
<p>In the Eco Theme <span class="file-name">index.html</span> file, we find the following code for the header and navigation:</p>
<pre class="html">&lt;div id="header"&gt;
  &lt;div id="logo"&gt;
    &lt;h1&gt;&lt;a href="index.html"&gt;
      &lt;img src="images/logo.gif"
        alt="The Eco Company Site Template logo" /&gt;
      &lt;/a&gt;&lt;/h1&gt;
  &lt;/div&gt;
  &lt;div id="contacts"&gt;
    &lt;!-- Contact informations here --&gt;
    &lt;p&gt;
      Call us on 001123456 &lt;br /&gt;
      &lt;a href="mailto:info@ecocompany-theme.com"&gt;
        info@ecocompany-theme.com
      &lt;/a&gt;
    &lt;/p&gt;
    &lt;!-- End of Contact informations --&gt;
  &lt;/div&gt;
  &lt;div class="clear"&gt;&lt;/div&gt;
  &lt;ul id="mainmenu"&gt;
   &lt;!-- Put your menu links here --&gt;
   &lt;li&gt;&lt;a href="index.html"&gt;Home&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="about-us.html"&gt;About Us&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;Services&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;Partners&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="contact.html"&gt;Contact&lt;/a&gt;&lt;/li&gt;
   &lt;!-- End of menu links --&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>You can update the contact info using SiteVars like I explained earlier. We will replace the navigation with a fragment to be dynamically updated as we add and delete pages from our site. But you don&#8217;t need to write a fragment. You can simply download this fragment set: <a href="http://www.skybluecanvas.com/exts/55">Fragments</a> and copy the entire directory to <span class="file-path">/skyblue/data/skins/eco/</span>.</p>
<p>After you have downloaded the fragment, we need to make one small change to the menu fragment. So open <span class="file-path">/fragments/menu/view.php</span> and Find the line that reads &lt;ul&gt; and change it to:</p>
<pre class="html">&lt;ul id="mainmenu"&gt;
</pre>
<p>We have simply added an ID to the UL element to match the Eco Theme style rules. I could have done this for you, but I wanted you to learn how to modify a fragment to match the template you are converting.</p>
<p>Now we can finish the header by adding the code to load the fragment when the page is created. We do that like this:</p>
<pre class="html">&lt;div id="header"&gt;
  &lt;div id="logo"&gt;
    &lt;h1&gt;&lt;a href="[[site.url]]"&gt;
      &lt;img src="images/logo.gif" alt="[[site.name]] logo" /&gt;
    &lt;/a&gt;&lt;/h1&gt;
  &lt;/div&gt;
  &lt;div id="contacts"&gt;
      &lt;!-- Contact informations here --&gt;
    &lt;p&gt;
      Call us at [[site.contact_phone]] &lt;br /&gt;
      &lt;a href="mailto:[[site.contact_email]]"&gt;
        [[site.contact_email]]
      &lt;/a&gt;
    &lt;/p&gt;
    &lt;!-- End of Contact informations --&gt;
  &lt;/div&gt;
  &lt;div class="clear"&gt;&lt;/div&gt;
  &lt;!--#plugin:fragment(menu,view)--&gt;
&lt;/div&gt;
</pre>
<p>Now our header is finished. If you are starting to suspect that this is pretty easy &#8211; you are right &#8211; it is.</p>
<p>I want to focus on helping you learn the concepts not convert a specific theme so we are going to skip the Scrolling Banner section for now. I have included the fragment required for that section in the file you just downloaded.</p>
<h2>The Main Content</h2>
<p>The main content, or body of a standard text page is created and edited in the <acronym title="What You See is What You Get">WYSIWYG</acronym> text editor in the Page Manager. We only need to tell SkyBlueCanvas where to place the content. This is accomplished using the Page Fragment that is included in the fragments download from earlier in this article.</p>
<p>The Page Fragment is just like any other fragment and is loaded the same way. So find the region of the Eco theme that the designer has designated as the maincontent area.</p>
<pre class="html">&lt;div id="main"&gt;
  &lt;div id="sidebar"&gt;
    &lt;!-- We will come back to the side bar shortly --&gt;
  &lt;/div&gt;

  &lt;div id="text"&gt;
    &lt;!-- Put your text here --&gt;

    &lt;!-- End of Text --&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The designer, Darinka, has conveniently labeled the content area with a comment indicating that to &#8220;Put your text here&#8221;, so that is what we will do. So delete the sample content she has placed between the comments, with our Page Fragment call like this:</p>
<pre class="html">&lt;div id="main"&gt;
  &lt;div id="sidebar"&gt;
    &lt;!-- We will come back to this --&gt;
  &lt;/div&gt;

  &lt;div id="text"&gt;
    &lt;!-- Put your text here --&gt;
    &lt;!--#plugin:fragment(page,view)--&gt;
    &lt;!-- End of Text --&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Now, when SkyBlueCanvas builds the page, it will replace the fragment call with the text we created for this page in the Page Manager.</p>
<h2>The Side Bar</h2>
<p>The side bar provides us with a good opportunity to talk a little about the usefulness of fragments and how to plan your pages when building or converting a skin for SkyBlueCanvas. We want updating our site to be as little work as possible. This means avoiding repeating or duplicating tasks and code. In fact, there is a concept in programming called <acronym title="Don't Repeat Yourself">DRY</acronym>.</p>
<p>Fragments allow us to write a single piece of code for regions of a page that will be the same for every page and every type of page. Typically our header, footer and often the side bar will be the same for every page, so we don&#8217;t want to duplicate the same code for every layout type we have. We can simply create a fragment and load the fragment in each layout style.</p>
<p>There is also even better news &#8211; fragments can be nested, so your fragments can also load fragments. For instance, if our side bar will include a Links List, we can have a side bar fragment which includes a fragment call to load the Links fragment. And this is exactly what we are going to create now.</p>
<p>I purposefully did not include the Sidebar Fragment in the download I gave you. I want you to experience writing a fragment of your own &#8211; and this is a very simple one.</p>
<p>Inside the <span class="file-path">/skyblue/data/skins/eco/fragments/</span> folder, create a new folder named <span class="file-name">sidebar</span>. Inside of this folder we need to create a sinlge PHP file named <span class="file-name">view.php</span>. View is the name of the default HTML output agent in a fragment. You can have an unlimited number of agents and you can name them anything you like, but we will use view for this example.</p>
<p>We want to inlude our Links List in the side bar, so our Sidebar Fragment View File needs to inlude the call to the Links Fragment. You are probably catching on by now and already know that we do this with the following code:</p>
<pre class="html">&lt;!--#plugin:fragment(links,view)--&gt;
</pre>
<p>Now you simply save the file. But wait, we have not actually called the Sidebar Fragment from within our page yet. We need to go back a bit and re-visit the code we modified to load the page text, and &#8211; as you probably guessed &#8211; add a fragment call to our Sidebar Fragment like this:</p>
<pre class="html">&lt;div id="main"&gt;
  &lt;div id="sidebar"&gt;
    &lt;!--#plugin:fragment(sidebar,view)--&gt;
  &lt;/div&gt;

  &lt;div id="text"&gt;
    &lt;!-- Put your text here --&gt;
    &lt;!--#plugin:fragment(page,view)--&gt;
    &lt;!-- End of Text --&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>If you recall, I said that <span class="file-name">view.php</span> is the default view of a fragment. So in our code above, the second parameter &#8216;view&#8217;, is not really necessary. We can load the default fragment view by simply calling:</p>
<pre class="html">&lt;!--#plugin:fragment(sidebar)--&gt;
</pre>
<p>The rest of this page, and the other page layouts can be converted in the same way that we have converted the elements above. I will leave the remaining elements and pages to you. You now have all of the tools you need to convert just about any HTML theme to work with SkyBlueCanvas.</p>
<p>Since I know this is your first theme conversion, I&#8217;m sure you will have questions. Please feel free to post questions in the <a href="http:forum.skybluecanvas.com">SkyBlueCanvas Forum</a>. I try to respond within 24 hours and usually much sooner than that.</p>
<h2>A Few Caveats</h2>
<p>In this article we covered converting a basic text page template for SkyBlueCanvas. What we did not cover, however, is how to create a layout for a contact form, photo gallery or other content page that includes non-text content in the body of the page.</p>
<p>This is actually quite easy to do, and there are two ways to do it. Whether your non-text page is a contact form, photo gallery or perhaps a Flash animation, they are all fragments and therefor loaded in the same way as every other fragment.</p>
<p>You have a choice with these fragments. You can create a new page layout that is specific to the content &#8211; <span class="file-name">skin.contact.html</span> &#8211; for instance, or you can just load the fragment in a standard text page, thus using only a single layout file.</p>
<h3>Required Skin Structure</h3>
<p>As you may be aware, in v1.1 we changed the way SkyBlueCanvas skins and content publishing works. The new format gives the site designer much greater flexibility and makes content publishing simpler for the site owner. We did not want to break compatibility with the old skin format so SkyBlueCanvas can still deal with both. In order to determine which skin format is being used, SkyBlueCanvas looks for the HTML closing tag &lt;/html&gt; in the skin for whichever page is being rendered. If the closing tag is not present, SkyBlueCanvas assumes the skin is a legacy skin.</p>
<p>What this means to you when building a skin is that if you are building a skin following the new format (which you most likely will be), you must include the &lt;/html&gt; tag in the skin.{skin_name}.html file (as opposed to in a fragment).</p>
<h3>Standard Page Approach</h3>
<p>If you want to use a single page layout for all of your pages, you can create non-text or text and fragment pages, by using the in-text fragment call to load your fragment. It is very simple to do. Create a new page, for instance Contact, then in the text editor in the Page Manager,include the following token:</p>
<pre class="html">{plugin:fragment(contacts,view)}
</pre>
<h3>Content-specific Layout Approach</h3>
<p>If you prefer to use a content-specific layout (or page type), you can simply duplicate your standard page, but rather than include the page fragment call in the main content area:</p>
<pre class="html">&lt;!--#plugin:fragment(page,view)--&gt;
</pre>
<p>Replace it with the call to the fragment for that page:</p>
<pre class="html">&lt;!--#plugin:fragment(contacts,view)--&gt;
</pre>
<p>And that&#8217;s it. You now know how to convert just about any HTML theme, with an unlimited number of layouts, to work with SkyBlueCanvas.</p>
<h2>A Final Note</h2>
<p>In <span class="admin-path">Admin &gt; Pages &gt; Editor</span>, you will find a Page Type selector on the Meta Data tab. The options in this selector correspond to your HTML layout files. So if you have two layouts, <span class="file-name">skin.default.html</span> and <span class="file-name">skin.contact.html</span>, the Page Type selector will have the options default and contact. You will need to be sure to select the Page Type you wish SkyBlueCanvas to use to build each page.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/converting-themes-skybluecanvas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Menus in SkyBlueCanvas v1.1</title>
		<link>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/creating-menus-skybluecanvas-v11/</link>
		<comments>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/creating-menus-skybluecanvas-v11/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 17:58:40 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Fragments]]></category>
		<category><![CDATA[SkyBlueCanvas CMS]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[fragment]]></category>
		<category><![CDATA[fragments]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[skin]]></category>
		<category><![CDATA[skins]]></category>
		<category><![CDATA[skybluecanvas]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[views]]></category>
<category>fragments</category><category>menus</category><category>skins</category><category>tutorials</category>
		<guid isPermaLink="false">http://blog.skybluecanvas.com/?p=53</guid>
		<description><![CDATA[When you create a new page in SkyBlueCanvas, a menu item is already created for you. In fact, there is not really a menu item to create because the system assumes, by default, that if you have created a page, there should be a menu link for. I mean, how else would anyone find your page if there is not link, right?]]></description>
			<content:encoded><![CDATA[<p>When you create a new page in SkyBlueCanvas, a menu item is already created for you. In fact, there is not really a menu item to create because the system assumes, by default, that if you have created a page, there should be a menu link to it. I mean, how else would anyone find your page if there is no link, right?</p>
<p>The only trouble is, which menu should the new page go in? This is where you will have to give SkyBlueCanvas a little help. On the Meta Data tab in the Page Manager (<span class="admin-path">Admin &gt; Pages &gt; Edit</span>), you will see a selector field labeled Menu. You simply select the menu in which you want the page to appear.</p>
<p>There are two logical next questions that you may have. (1) How do I create a new menu? (2) How does the menu get placed on a page? In this article I will answer these two questions.</p>
<p>The answer to question (1), &#8220;How do I create a new menu?&#8221; is very simple. You simply navigate to <span class="admin-path">Admin &gt; Collections &gt; Menus</span>. From the list view, click the &#8220;Add&#8221; button. In the form that appears:</p>
<p><img class="diagram" src="http://blog.skybluecanvas.com/images/menu.form.jpg" alt="Menu Manager form image" width="464" height="184" /></p>
<p>provide the requested information.</p>
<div class="msg-info">
<h2>Note</h2>
<p>The Menu Type property has been deprecated so you do not need to complete this field.</p>
</div>
<div class="msg-info">
<h2>Tip</h2>
<p>You will need to know the numeric ID of the new menu so make note of it and hold onto it.</p>
</div>
<p>Then click Save.</p>
<p>No you can go back to <span class="admin-path">Admin &gt; Pages &gt; Edit</span> (your page) and on the Meta Data tab, select your new menu from the options list and save your page.</p>
<p>You have now successfully created a new menu and added a page (menu item) to the new menu.</p>
<h2>Displaying a Menu</h2>
<p>Displaying your menu involves two other concepts in SkyBlueCanvas: <a href="http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-v11-rc1-skins-explained/">templates</a> and <a href="http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-fragments-explained/">fragments</a>.</p>
<p>Templates and fragments make up the presentation or &#8220;view&#8221; portion of your web page. They are where you define the HTML structure of pages (templates) and collections or content types (fragments). They may be a little tricky to grasp at first, but once you understand them, they are very powerful and flexible.</p>
<p>Your SkyBlueCanvas installation, provided you are using v1.1 RC1 or later, should already have a Menu Fragment included. We are going to modify this fragment, or add to it rather, first.</p>
<p>Using your FTP client, navigate to <span class="file-path">/skyblue_root/data/skins/techjunie/fragments/menu/</span> and make a copy of <span class="file-name">view.php</span>. Name the new file <span class="file-name">mymenu.php</span>. Then open the file with the text editor of your choice.</p>
<div class="msg-info">
<h2>Tip</h2>
<p>If you have installed your own skin, you can simply copy <span class="file-path">/skyblue_root/data/skins/techjunkie/fragments/</span> to your new skin.</p>
</div>
<p>In the file <span class="file-name">mymenu.php</span> you will see the following code:</p>
<pre class="php">&lt;?php
  global $Router;
  global $Filter;
?&gt;
&lt;div class="horizontal-menu"&gt;
  &lt;?php if (count($data)) : ?&gt;
  &lt;ul&gt;
    &lt;?php foreach ($data as $item) : ?&gt;
    &lt;?php if (not_valid_menu($item)) continue; ?&gt;
    &lt;li&lt;?php the_class($item); ?&gt;&gt;
      &lt;a href="&lt;?php the_link($item); ?&gt;"&gt;
          &lt;?php the_text($item); ?&gt;&lt;/a&gt;
    &lt;/li&gt;
    &lt;?php endforeach; ?&gt;
  &lt;/ul&gt;
  &lt;?php endif; ?&gt;
&lt;/div&gt;</pre>
<p>That looks pretty simple, huh?</p>
<p>We are going to need to modify the code a little bit but I promise it will be painless- and I will give you the full code when we are finished.</p>
<p>SkyBlueCanvas will know that this is a menu fragment (more on this later) so the menu items (actually the pages) will already be available to your code in the <span class="variable">$data</span> variable. We will only need to manually retrieve our new menu.</p>
<p>Now you can refer back to the Menu ID I asked you to hold onto.</p>
<pre class="php">&lt;?php

  /*
  * Set this to the ID of the menu you created
  */

  $my_menu_id = 3;

  /*
  * Get the new menu from storage
  */

  $menu = $Core-&gt;SelectObj(
    $Core-&gt;xmlHandler-&gt;ParserMain(SB_XML_DIR . "menus.xml"),
    $my_menu_id
  );
?&gt;</pre>
<p>Now we have our menu items and our new menu. We can start building the menu HTML.</p>
<p>We will start with a basic HTML structure:</p>
<pre class="php">&lt;div class="mymenu"&gt;
  &lt;?php if ($menu-&gt;showtitle) : ?&gt;
  &lt;h2&gt;&lt;?php echo $menu-&gt;title; ?&gt;&lt;/h2&gt;
  &lt;?php endif; ?&gt;
  &lt;ul class="verticalmenu"&gt;

  &lt;/ul&gt;
&lt;/div&gt;</pre>
<p>That&#8217;s not too bad. We are almost finished building our menu HTML. Now all we need to do is loop through the <span class="variable">$data</span> list, and display each of the items in our menu. Here is how the looping is done:</p>
<pre class="php">  &lt;?php foreach ($data as $item) : &gt;

  &lt;?php endforeach; ?&gt;</pre>
<p>We only want to show links to pages that are published, so we will add a single line to make sure the menu item can be displayed:</p>
<pre class="php">  &lt;?php foreach ($data as $item) : &gt;
  &lt;?php if (not_valid_menu($item)) continue; ?&gt;

  &lt;?php endforeach; ?&gt;</pre>
<p>Now we want to filter the <span>$data</span> items to only show items in our new menu. We do this with a single line of code:</p>
<pre class="php">  &lt;?php foreach ($data as $item) : &gt;
  &lt;?php if (not_valid_menu($item)) continue; ?&gt;
  &lt;?php if ($item-&gt;menu != $menu-&gt;id) continue ; ?&gt;

  &lt;?php endforeach; ?&gt;</pre>
<p>Wow! That was pretty easy and we are moving right along &#8230;</p>
<p>The only thing we have left to do is display the menu item:</p>
<pre class="php">  &lt;?php foreach ($data as $item) : &gt;
  &lt;?php if (not_valid_menu($item)) continue; ?&gt;
  &lt;?php if (!$item-&gt;menu == $my_menu_id) continue ; ?&gt;
  &lt;li&lt;?php the_class($item); ?&gt;&gt;
    &lt;a href="&lt;?php the_link($item); ?&gt;"&gt;
        &lt;?php the_text($item); ?&gt;&lt;/a&gt;
  &lt;/li&gt;
  &lt;?php endforeach; ?&gt;</pre>
<p>And believe it or not, you have  just built a new menu, as well as your first SkyBlueCanvas Fragment. There is only one last step, and this one is the simplest of all.</p>
<p>Up to this point, we have created a new Menu object in the SkyBlueCanvas admin and written a new menu Fragment. The only thing that remains is to tell SkyBlueCanvas where to display the fragment. To do this, go to <span class="file-path">/skyblue_root/data/skins/techjunkie/</span> (or your skin) and open <span class="file-name">skin.text.html</span> in your text editor. You will see the following code:</p>
<pre class="html">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" {doc:lang}&gt;
  &lt;head&gt;
    &lt;title&gt;[[page.title]]&lt;/title&gt;
    &lt;meta http-equiv="Content-Type"
      content="text/html;charset=UTF-8" /&gt;
    &lt;?php echo $this-&gt;get_meta_data(); ?&gt;
    &lt;link rel="stylesheet"
    type="text/css"
    href="&lt;?php echo $this-&gt;get_path(); ?&gt;css/TechJunkie.css" /&gt;
    &lt;!--#plugin.preloader--&gt;
  &lt;/head&gt;
  &lt;body id="homepage"&gt;
    &lt;div id="wrap"&gt;
      &lt;!--#plugin:fragment(header)--&gt;
      &lt;div id="menu"&gt;
        &lt;!--#plugin:fragment(menu,view,menu=1)--&gt;
      &lt;/div&gt;
      &lt;div id="content-wrap"&gt;
        &lt;div id="main"&gt;
          &lt;!--#plugin:fragment(page,view)--&gt;
        &lt;/div&gt;
        &lt;div id="sidebar"&gt;
          &lt;!--#plugin:fragment(sidebar)--&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div id="footer-wrap"&gt;
        &lt;!--#plugin:fragment(footer)--&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Notice the lines that look like this:</p>
<pre class="html">&lt;!--#plugin:fragment(page,view)--&gt;&gt;</pre>
<p>These tokens are the code that tell SkyBlueCanvas where to load a fragment, which fragment to load, and which view (PHP file) to load. So the only thing you need to do is add a token for your new menu in the location in the HTML where you want the menu to appear. Let&#8217;s assume you want your new menu to appear at the top of the sidebar. You will change the code to look like this:</p>
<pre class="html">
<div id="sidebar">
 &lt;!--#plugin:fragment(menu,mymenu)--&gt;</div>
</pre>
<p>Now test your new menu by pointing your browser to your web site. Your new menu should appear at the top of the sidebar.</p>
<div class="msg-info">
<h2>Note</h2>
<p>You will need to make this change for all of the skins HTML files, <span class="file-name">skin.contacts.html</span> and <span class="file-name">skin.standard.html</span>.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/creating-menus-skybluecanvas-v11/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>SkyBlueCanvas Fragments Explained</title>
		<link>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-fragments-explained/</link>
		<comments>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-fragments-explained/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 06:18:14 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Fragments]]></category>
		<category><![CDATA[SkyBlueCanvas CMS]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[fragments]]></category>
		<category><![CDATA[skybluecanvas]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[views]]></category>
<category>fragments</category><category>skins</category><category>tutorials</category>
		<guid isPermaLink="false">http://blog.skybluecanvas.com/?p=51</guid>
		<description><![CDATA[The key buidling dynamic content into a SkyBlueCanvas site is what we call fragments. An easy way to think about fragments is as a piece of a page. The fragment code creates the HTML for a particular data type. For instance, if you have a collection of Links you want to display on your site, the Links Fragment will take care of generating the HTML. One neat thing about fragments, though, is that a single fragment can have numerous different HTML formats.]]></description>
			<content:encoded><![CDATA[<p>The key buidling dynamic content into a SkyBlueCanvas site is what we call fragments. An easy way to think about fragments is as a piece of a page. The fragment code creates the HTML for a particular data type. For instance, if you have a collection of Links you want to display on your site, the Links Fragment will take care of generating the HTML. One neat thing about fragments, though, is that a single fragment can have numerous different HTML formats.</p>
<p>Creating a basic fragment is pretty simple. You simply go to <span class="file-path">/your_skyblue_root/data/skins/your_skin/</span> and create a new folder named fragments. Inside this folder, you create another folder named links. There are two pre-defined files that you can create in this folder but both are optional.</p>
<h3>functions.php</h3>
<p>If you create a file named functions.php in your <span class="file-path">/fragments/your_fragment/</span> folder, SkyBlueCanvas will load this file automatically before loading your fragment. This allows you to creat more robust fragments without cluttering your presentation code with a lot of logic.</p>
<h3>view.php</h3>
<p>view.php is the default fragment view name. You can name your views anything you like. The significance of the view.php file will be explained a little later on when we talk about Loading Fragments in a web page.</p>
<p>By default, SkyBlueCanvas will attempt to figure out which data set to make available to your fragment view. It does this by matching the fragment name (for instance Links) with an existing data set. If the fragment name correspongs to an Admin Manager name, that data set will be loaded and made available to your fragment view in a variable named $data. For very simple fragments that use a single data set, this means you don&#8217;t need to write any code to retrieve the data set.</p>
<h3>About Data Sets</h3>
<p>SkyBlueCanvas stores data objects in an XML file named according to the Admin Manager that manages that data set. Using our Links Manager as an example, SkyBlueCanvas stores Links data in <span class="file-path">/skyblue_root/data/xml/links.xml</span>.</p>
<p>If the Admin Manager also has groups associated with the data objects, then the data is usually stored in a file named [data]groups.xml. Again using the Links Manager as an example, the Links Groups are stored in <span class="file-path">/skyblue_root/data/xml/linksgroups.xml</span>.</p>
<h2>A Simple Example</h2>
<p>Theory is wonderful, but examples are perhaps more useful so let&#8217;s create a simple fragment so you can get the hang of it.</p>
<p>If you do not have a folder named fragments in your skin folder, create it now. Inside that directory, create a new directory named links. The, inside the links folder, create two PHP files: <span class="file-name">functions.php</span> and <span class="file-name">view.php</span>.</p>
<p>This is not a lesson on writing PHP, so I will just give you the code to paste into <span class="file-name">functions.php</span>:</p>
<pre class="php">&lt;?php

function get_published(&amp;$items) {
  $pub = array();
  foreach ($items as $item) {
    if (!isset($item-&gt;published)) {
      array_push($pub, $item);
    }
    else if ($item-&gt;published) {
      array_push($item-&gt;published);
    }
  }
  return $pub;
}

function get_items(&amp;$group, $items) {
  $items = get_published($items);
  $these = array();
  foreach ($items as $item) {
    <del datetime="2010-05-09T15:46:52+00:00">if ($item-&gt;group == $group-&gt;id) {</del>
    if ($item-&gt;groups == $group-&gt;id) {
      array_push($these, $item);
    }
  }
  return $these;
}

?&gt;</pre>
<h3>The View</h3>
<p>The view is where the data items are transformed into HTML. A little bit of PHP is required, however, to make sure we have all the data we need. So past the following code into <span class="file-name">view.php</span>:</p>
<pre class="php">&lt;?php
  global $Core;
  global $Filter;

  $groups = get_published(
    $Core-&gt;xmlHandler-&gt;ParserMain(
      "data/xml/linksgroups.xml"
    )
  );

  $items = get_published($data);
  unset($data);
?&gt;</pre>
<p>This code is very easy to understand. First, we declare the Core and Filter objects as global. This allows us to access these items which were created in the global scope of the PHP script (index.php).</p>
<p>in the next section of the code, we are getting all of the published groups, by calling get_published (from functions.php) with the output of the xmlHandler.</p>
<p>In the last piece of code, we are fitlering our complete list of data items in $data, by getting the published links with get_published.</p>
<p>Then, just for good house-keeping, we unset the $data variable because it is no longer needed.</p>
<h3>The Output</h3>
<p>The next bit creates the actual output using our data items and groups.</p>
<pre class="php">&lt;div&gt;
  &lt;?php foreach ($groups as $group) : ?&gt;
    &lt;?php $data = get_items($group, $items); ?&gt;
    &lt;h2&gt;
      &lt;?php echo $group-&gt;name; ?&gt;
    &lt;/h2&gt;
    &lt;ul class="links"&gt;
      &lt;?php if (count($data)) : ?&gt;
        &lt;?php foreach ($data as $obj) : ?&gt;
          &lt;li&gt;
            &lt;a href="&lt;?php echo $obj-&gt;url; ?&gt;"&gt;
              &lt;?php echo $obj-&gt;name; ?&gt;
            &lt;/a&gt;
          &lt;/li&gt;
        &lt;?php endforeach; ?&gt;
      &lt;?php endif; ?&gt;
    &lt;/ul&gt;
  &lt;?php endforeach; ?&gt;
&lt;/div&gt;</pre>
<p>Let&#8217;s look at this block of code in smaller pieces. In the outer-most block of code, we are simply looping through all of the groups. Each pass through the loop, the next group is stored in the $group variable so we can access it&#8217;s data.</p>
<pre class="php">&lt;div&gt;
  &lt;?php foreach ($groups as $group) : ?&gt;

  &lt;?php endforeach; ?&gt;
&lt;/div&gt;</pre>
<p>In the next block, we are retrieving all of the items in the current group:</p>
<pre class="php">&lt;div&gt;
  &lt;?php foreach ($groups as $group) : ?&gt;
    &lt;?php $data = get_items($group, $items); ?&gt;

  &lt;?php endforeach; ?&gt;
&lt;/div&gt;</pre>
<p>And finally, we loop through each item in $items. Each pass through the loop, the next item is stored in the $item variable.</p>
<pre class="php">&lt;div&gt;
  &lt;?php foreach ($groups as $group) : ?&gt;
    &lt;?php $data = get_items($group, $items); ?&gt;
    &lt;h2&gt;&lt;?php echo $group-&gt;name; ?&gt;&lt;/h2&gt;
    &lt;ul class="links"&gt;
      &lt;?php if (count($data)) : ?&gt;
        &lt;?php foreach ($data as $obj) : ?&gt;
          &lt;li&gt;
            &lt;a href="&lt;?php echo $obj-&gt;url; ?&gt;"&gt;
              &lt;?php echo $obj-&gt;name; ?&gt;
            &lt;/a&gt;
          &lt;/li&gt;
        &lt;?php endforeach; ?&gt;
      &lt;?php endif; ?&gt;
    &lt;/ul&gt;
  &lt;?php endforeach; ?&gt;
&lt;/div&gt;</pre>
<p>You will notice that there is HTML code mixed with the PHP code. When view.php is loaded, the PHP will be executed and merged with the HTML.</p>
<h3>The Full Code</h3>
<pre class="php">&lt;?php
  global $Core;
  global $Filter;

  $groups = get_published(
    $Core-&gt;xmlHandler-&gt;ParserMain(
      "data/xml/linksgroups.xml"
    )
  );

  $items = get_published($data);
  unset($data);
?&gt;
&lt;div&gt;
  &lt;?php foreach ($groups as $group) : ?&gt;
    &lt;?php $data = get_items($group, $items); ?&gt;
    &lt;h2&gt;&lt;?php echo $group-&gt;name; ?&gt;&lt;/h2&gt;
    &lt;ul class="links"&gt;
    &lt;?php if (count($data)) : ?&gt;
      &lt;?php foreach ($data as $obj) : ?&gt;
        &lt;li&gt;
          &lt;a href="&lt;?php echo $obj-&gt;url; ?&gt;"&gt;
            &lt;?php echo $obj-&gt;name; ?&gt;
          &lt;/a&gt;
        &lt;/li&gt;
      &lt;?php endforeach; ?&gt;
    &lt;?php endif; ?&gt;
    &lt;/ul&gt;
  &lt;?php endforeach; ?&gt;
&lt;/div&gt;</pre>
<h2>Loading Fragments</h2>
<p>Well, the hard part is over. All we need to do now is tell SkyBlueCanvas where to load the fragment. This is very easy and there are two ways to do it.</p>
<p>You can load fragments as part of a template or within the body (text) of a page. To load a fragment as part of the template, you simply include the following code in the the desired location of the template:</p>
<pre class="html">&lt;!--#plugin:fragment(links,view)--&gt;</pre>
<p>If you recall, however, I stated earlier that view.php is the default view file, so the view argument in the code just given is not needed. So you can load the links fragment with this code:</p>
<pre class="html">&lt;!--#plugin:fragment(links)--&gt;</pre>
<p>If you want to display your links in the body of a page or text article, you can do so by inserting the following token in the body of your page text:</p>
<pre class="html">{plugin:fragment(links)}</pre>
<p>You can try this technique out by going to Admin &gt; Pages and inserting the token above in the page text.</p>
<h3>Caveats</h3>
<p>In order for the fragments to work, you will need to make sure that the PluginParser and FragmentsPlugin are enabled. To do this, go to Admin &gt; Collections &gt; Plugins and make sure plugin.parser.php and plugin.fragments.php are loaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/skybluecanvas-fragments-explained/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
