<?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; Fragments Archives  &#8211; SkyBlueCanvas</title>
	<atom:link href="http://blog.skybluecanvas.com/topics/skybluecanvas-lightweight-cms/fragments-skybluecanvas-lightweight-cms/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>Fragmentor Plugin for SkyBlueCanvas</title>
		<link>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/plugins/fragmentor-plugin-skybluecanvas/</link>
		<comments>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/plugins/fragmentor-plugin-skybluecanvas/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 01:19:46 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Fragments]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[fragment]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[s]]></category>
		<category><![CDATA[skin]]></category>
		<category><![CDATA[skins]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[variable]]></category>
		<category><![CDATA[views]]></category>
<category>extensions</category><category>fragments</category><category>plugins</category><category>skins</category><category>templates</category><category>themes</category>
		<guid isPermaLink="false">http://blog.skybluecanvas.com/?p=59</guid>
		<description><![CDATA[Fragmentor is a plugin to be used instead of or alongside the default Fragment Plugin in SkyBlueCanvas. Fragmentor provides template and fragment developers an alternative and much more flexible syntax for loading dynamic content views (fragments) into SkyBlueCanvas web pages. Since the plugin uses a different syntax from the default fragment plugin, it will not conflict with it. With Fragmentor, you can pass an arbitrary number of key=&#60; value pairs of data from your article text or template file.]]></description>
			<content:encoded><![CDATA[<p>For a really cool Fragmentor usage example, check out my blog post on the <a href="http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/editable-sidebar-content-hack/" title="Editable Sidebar Hack">Editable Sidebar Content Hack</a></p>
<h2>System Requirements</h2>
<ul>
<li>SkyBlueCanvas v1.1</li>
<li>PHP 5 (Not tested with PHP 4)</li>
<li>Apache Web Server</li>
</ul>
<div class="msg-info">
<h2>Important</h2>
<p>Unlike most SkyBlueCanvas Plugins, the Fragmentor Plugin <strong><em>must</em></strong> be installed manually via FTP. If you install this Plugin through the admin console, it will not function properly.</p>
</div>
<h2>Installation Instructions</h2>
<ol>
<li>Connect to your SkyBlueCanvas web site using the FTP Client of your choice.</li>
<li>Locate the Fragmentor Plugin file in <span style="text-decoration: underline;">source/plugin_fragmentor/plugin.fragmentor.php</span> in this download.</li>
<li>Upload the Fragmentor Plugin file to <span style="text-decoration: underline;">/skyblue_root/data/plugins/</span>.</li>
</ol>
<h2>Usage</h2>
<p>The Fragmentor Plugin allows you to pass a standard query string, similar to a URL query string, to your custom SkyBlueCanvas fragments. A query string is simply a string of key=&gt;value pairs in the format:</p>
<pre class="html">key1=value1&amp;key2=value2</pre>
<h2>Reserved Keywords</h2>
<p>The Fragmentor Plugin has 2 reserved keywords:</p>
<ol>
<li> name<em> &#8211; name</em> tells Fragmentor which Fragment to laod.</li>
<li> view<em> &#8211; view</em> tells Fragmentor which Fragment View to load.</li>
</ol>
<h2>Syntax</h2>
<p>You can use one of or a mix of two call syntaxes to call the Fragmentor Plugin:</p>
<h3>HTML Comment Syntax:</h3>
<pre class="html">&lt;!--fragment(name=fragment_name&amp;view=view_name&amp;key1=value1)--&gt;</pre>
<p>Use this syntax to add Fragmentor calls to your HTML skin templates.</p>
<h3>In-line Text Syntax:</h3>
<pre class="html">{fragment(name=fragment_name&amp;view=view_name&amp;key1=value1)}</pre>
<p>Use this syntax to add Fragmentor calls in-line in your page article text.</p>
<p>If you are familiar with SkyBlueCanvas Fragments, you know that the default Fragment Plugin attempts to load any data objects associated with the fragment automatically. The plugin determines the data to load based on the name of the fragment. For instance, if you have the Links Manager installed on your SkyBlueCanvas site, and you create a fragment named <em>links</em>, the Fragment Plugin will automatically load the <em>links</em> data objects. The data objects are passed to your fragment in a variable named $data;</p>
<p>Fragmentor maintains this automatic data loading and your data is still passed in the $data variable. Fragmentor, however, adds a new variabled named $params which is a keyed (associative) array corresponding to the key=&gt;value pairs of your query string.</p>
<p>Your query string can contain as many key=&gt;value pairs as you like and your key names can be anything you like. The only limitations are:</p>
<ol>
<li>The <em>name</em> and <em>view</em> keywords are reserved by the plugin</li>
<li>Your query string must be a well-formed query string meaning it must follow the rules or a standard URL query string (no spaces, no special characters, etc.)</li>
</ol>
<div class="msg-info">
<h2>Important</h2>
<p>Existing SkyBlueCanvas fragments are not currently configured to work with the Fragmentor Plugin. Fragmentor is intended to give you more flexibility in creating<strong><em> your custom plugins</em></strong>. We may eventually merge Fragmentor with the core SkyBlueCanvas code but at the present time it should be considered and treated like any other third-party add-on.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/plugins/fragmentor-plugin-skybluecanvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Editable Sidebar Content Hack</title>
		<link>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/editable-sidebar-content-hack/</link>
		<comments>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/editable-sidebar-content-hack/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 00:27:48 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Fragments]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[SkyBlueCanvas CMS]]></category>
		<category><![CDATA[fragment]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[region]]></category>
<category>content</category><category>fragments</category><category>hack</category><category>hacks</category><category>plugins</category><category>region</category>
		<guid isPermaLink="false">http://blog.skybluecanvas.com/?p=58</guid>
		<description><![CDATA[A few nights ago, Steve Fister, one of the SkyblueCanvas Development Team Members posed the question again and offered a few ideas on how to pull it off. After thinking about Steve's suggetions, I realized that this is actually quite easy to do. In fact, with Steve's idea, you can add an editable text block anywhere on a web page. What's more, with a little SkyBlueCanvas Skin Magic, you can build page-specific text blocks, so if you want a different block of text to appear on different pages, you can do it with this trick.]]></description>
			<content:encoded><![CDATA[<p>
Several users of the <a href="http://forum.skybluecanvas.com/" rel="nofollow"  title="SkyBlueCanvas Forum">SkyBlueCanvas Forum</a> have asked how to add an editable text block to the sidebar of their site. I puzzled over this question and to date had informed folks that unfortunately it cannot be done.
</p>
<p>
A few nights ago, Steve Fister, one of the SkyblueCanvas Development Team Members posed the question again and offered a few ideas on how to pull it off. After thinking about Steve&#8217;s suggetions, I realized that this is actually quite easy to do. In fact, with Steve&#8217;s idea, you can add an editable text block anywhere on a web page. What&#8217;s more, with a little SkyBlueCanvas Skin Magic, you can build page-specific text blocks, so if you want a different block of text to appear on different pages, you can do it with this trick.
</p>
<p>
Out-of-the-box, this is still not possible with SkyBlueCanvas, but I have been working on a new Plugin that &#8211; unbeknownst to me when I built it &#8211; is the missing piece. The plugin is called <strong>Fragmentor</strong> and is a super-charged version of the <strong>Fragment Plugin</strong> that comes pre-installed with SkyBlueCanvas.
</p>
<h2>About Fragmentor</h2>
<p>
The existing <strong>Fragment Plugin</strong> has one design limitation: it uses pre-defined parameters whose meaning is determined by both position and name. I built the super-charged <strong>Fragmentor Plugin</strong> to correct this design mistake and to make the plugin much more flexible.
</p>
<p>
Whereas one would load a Fragment with the old <strong>Fragment Plugin</strong> with a call like this:
</p>
<pre class="html" style="font-size: 10px">
&lt;!--#plugin:fragment(fragment_name,view_name,
    match_param[id1,id2,...],
    page=[id1,id2,...]})--&gt;
</pre>
<p>
The new plugin uses a query string of key=&gt;value pairs much like a URL query string that looks like this:
</p>
<pre class="html" style="font-size: 10px">
{fragment(name=fragment_name&#038;view=view_name
    &#038;param1=value1&#038;param2=value2)}
</pre>
<div class="msg-info">
<h2>Note:</h2>
<p>
You cannot break fragment call tokens onto more than one line. They are broken onto multiple lines in this example to fit the format of this page.
</p>
</div>
<p></p>
<p>
There are 3 benefits of this approach:
</p>
<ol>
<li>The position of parameters is irrelevant</li>
<li>The query string can contain an arbitrary number of key=&gt;value pairs</li>
<li>Only your fragment needs to understand the optional parameters*</li>
</ol>
<p>
* There are two exceptions to this rule: the <em>name</em> and <em>view</em> keywords are reserved. Some might call this a shortcoming but I tend to disagree. Every language, whether for markup or code execution, uses reserved keywords so we are not introducing a new concept by reserving these two keywords.
</p>
<h2>The <strong>Editable Text Anywhere</strong> Trick.</h2>
<h3>What You Will Need</h3>
<ul>
<li>The <a href="http://www.skybluecanvas.com/exts/82" rel="nofollow"  title="Editable Region Hack Download">Editable Region Hack Package Download</a></li>
<li>Basic PHP and HTML know-how</li>
<li>A SkyBlueCanvas web site</li>
<li>FTP access to your site</li>
<li>A text editor</li>
</ul>
<p>
First, <a href="http://www.skybluecanvas.com/exts/82" rel="nofollow"  title="Download Fragmentor Plugin">download the Editable Region Hack Package</a>. Follow the installation instructions included with the download.
</p>
<p>
Next, open one of your <strong>SkyBlueCanvas Skins</strong> in a text editor. We are going to use the sidebar for this demonstration, so in the sidebar of your template, add the following code:
</p>
<pre class="html">
{fragment(name=region&#038;view=view
    &#038;content_id=
    &lt;?php $this->get_page_name(); ?&gt;-sidebar)}
</pre>
<p>
For the time being, don&#8217;t worry about what this code means. After we have created our content item to display in the region, I will explain how this code works.
</p>
<h2>Now for the Trick</h2>
<p>
We are actually going to use a SkyBlueCanvas Page for our editable content that goes in this region. However, we will only be using the <strong>Page Menu Text</strong> and the <strong>Page Article Text</strong> in the region. The reason we created an empty Skin File was so our page does not get rendered as a full HTML document.
</p>
<p>
The <strong>Page Menu Text</strong> is what SkyBlueCanvas&#8217;s <strong>Router Class</strong> uses as it&#8217;s unique identifier, so we will need to use this as well. The Fragment code I told you not to worry about earlier comes into play now. If you look at the code, you will see a PHP call embedded in the Fragment call. When this page is loaded, the template PHP will be parsed before the Plugins are fired, so when the <strong>Fragmentor Plugin</strong> sees this page, the PHP code will be replaced by the <strong>Menu Text</strong> or unique identifier of the current page. So if we are currently viewing the &#8220;Home Page&#8221;, the final key=&gt;value pair in our query string will actually read:
</p>
<pre class="html">
content_id=home-page-sidebar
</pre>
<p>
This is critical in order for the trick to work.
</p>
<h2>The Finale</h2>
<p>
With all of our pieces in place, log into the admin section of your site and navigate to <strong>Admin &gt; Pages</strong> and click the <em>Add Page</em> button. Once in the <em>Page Form View</em>, click the <em>Meta Tab</em> and name your content item <strong>Home Page Sidebar</strong>.
</p>
<p>
In the selector labeled <em>Layout</em>, select <em>Region</em>. This tells SkyBlueCanvas to use our empty Region Skin to build this page. Since the Region Skin is empty, the only output of the page will be the article cotnent.
</p>
<p>
In the selector labeled <em>Menu</em>, select <em>No Menu</em> (this is important).
</p>
<p>
Set <em>Published</em> to <em>No</em>.
</p>
<p>
You can choose to syndicate this content item.
</p>
<p>
Finally, click the <em>Article Text</em> tab and enter text and images the same as you would on a SkyBlueCanvas page. Once you have finished entering your text, click the <em>Save button</em>, then view your home page. You should see your newly created content in the side bar.
</p>
<h3>Important</h3>
<p>
We are exploiting SkyBlueCanvas&#8217;s Unique Identifier format to match content items with the including page so it is critical that your editable region content Menu Text match the Menu Text of the including page exactly, except for the additional &#8217;sidebar&#8217; bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.skybluecanvas.com/skybluecanvas-lightweight-cms/editable-sidebar-content-hack/feed/</wfw:commentRss>
		<slash:comments>5</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>
