Archive

Archive for the ‘CFWheels’ Category

Make an RSS Feed for Your Splash Site

March 6th, 2010

Using the new Splash Tags for the Splash CMS, you can easily make an RSS feed or an XML sitemap.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<cfcontent type="text/xml" reset="Yes"><?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <atom:link href="http://www.YourSite.com/index.cfm/feed"
   rel="self" type="application/rss+xml" />
  <title>YourSite.com</title>
  <link>http://www.YourSite.com</link>
  <description>Your Description Goes Here</description>
  <cfoutput>
    <pubDate>#HTMLEditFormat(DateFormat(now(), 'ddd, dd mmm yyyy'))#
      #HTMLEditFormat(TimeFormat(now(), 'HH:mm:ss'))# EST</pubDate>
  <language>en-us</language>
  <ttl>40</ttl>
  <s:find slug="blog">
  <s:children-each order="publishedAt desc" where="status='published'">
    <item>
      <cfset thisChild = request.tags.currentChild>
      <title>#HTMLEditFormat(thisChild.title)#</title>
      <description><![CDATA[<s:content part="body" page="#thisChild#"/>]]></description>
      <pubDate>#HTMLEditFormat(DateFormat(thisChild.publishedAt, 'ddd, dd mmm yyyy'))#
         #HTMLEditFormat(TimeFormat(thisChild.publishedAt, 'HH:mm:ss'))# EST</pubDate>
      <guid isPermaLink="true">http://www.yoursite.com/index.cfm/#thisChild.slug#</guid>
      <link>http://www.yoursite.com/index.cfm/#thisChild.slug#</link>
    </item>
  </s:children-each>
  </s:find>
</channel></cfoutput>
</rss></cfcontent><cfabort>

Most of this code is the required RSS XML. Just drop in your site-specific domain name, description, etc.

The <s:find slug=”blog> tag finds the blog, and then <s:children-each> loops over all the children that are under the blog page. I used thisChild as a convenience variable instead of having to type request.tags.currentChild every time. The <cfabort> at the end keeps Splash from adding extra HTML tags at the end of the file.

You could also create an easy XML site map using a similar approach. Just change out the XML wrapper.

Clarke Bishop CFWheels, ColdFusion, Splash CMS , ,

New Splash Tags for the Splash CMS

March 5th, 2010

I recently added several new Splash Tags for the Splash content management system. If you don’t know about Splash, read my Introduction to Splash article.

  • <s: find>
  • <s: children-each>
  • <s: children-first >
  • <s: children-last >
  • <s: ifFirst >
  • <s: unlessFirst >
  • <s: ifLast >
  • <s: unlessLast >

There’s a complete list of tags and documentation over on the GitHub Wiki. But, I’ll give you an overview and show you how to use these tags for a blog.

<s:find> This tag looks up a page and stores the page object so that subsequent tags can use that page object.

<s: children-each> The tag finds all the children of a page and loops over them.

<s: children-first > and <s: children-last > finds the first or last child page.

The rest of the tags are all used inside of a <s: children-each> tag. They check to see if the current child page is the first one, last one, or whatever.

Making a Blog page with Splash Tags

Let’s say you have a page named Blog, that has several posts that are child pages of Blog. Then, in the body for the blog page, put something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<h3>Articles</h3>
<s:find slug="blog">
  <s:children-each
  order="publishedAt desc"
  where="status='published'">
    <cfset thisChild = request.tags.currentChild>
    <cfoutput>
      <dt class="blogList">
         <a href="#thisChild.slug#">#thisChild.title#</a>
            | #DateFormat(thisChild.publishedAt, 'long')#</dt>
      <dd class="blogDesc">#thisChild.description#</dd>
    </cfoutput>
  </s:children-each>
</s:find>

<s:find slug=”blog”> finds the blog page, and then <s:children-each> loops over all the pages. By the way, <s:children-each> uses the CFWheels findAll model method, so all of the cool CFWheels parameters are available in <s:children-each>!

If you want to see an example of what this looks like, visit the DonorUp blog page.

All in all, that’s a lot of output for very little programming effort. That’s what I call the secret to programmer happiness!

Clarke Bishop CFWheels, ColdFusion, Splash CMS , ,

Content Management and the Splash CMS — Introduction

March 5th, 2010

Splash CMS is an open source content management system that runs on top of CFWheels. It’s designed to be a simple, but elegant content management solutions for websites that are managed by small teams.

CFWheels is an open source ColdFusion framework that is inspired by Ruby on Rails. Besides being easy to use and learn, using CFWheels lets you adapt great ideas from Ruby on Rails (RoR) applications. RoR has the Radiant CMS, and Splash is the ColdFusion/CFWheels adaptation!

You can easily download Splash from http://wiki.github.com/russjohnson/SplashCMS/. The documentation for Splash is still kind of sparse, but the Radiant documentation is mostly applicable, and you can easily see how most things are supposed to work. Then, if you get stuck, email the Google Group.

Splash Layouts, Snippets, and Pages

Splash uses Layouts, Snippets, and Pages to build a website.

A layout, as you might imagine, is like a skin for an entire website. You can have multiple layouts and use different layouts for different pages.

Pages are specific URLs on a Splash site, and each page has a specific layout specified. A page can have multiple “page parts.” Most pages will have a “Body” part, but some might also have a “Sidebar” or other parts.

Snippets are reusable content chunks. You might have a navigation snippet that displays the main navigation for your site. Headers and Footers are other common snippets.

Splash Tags

There is one other very powerful component to Splash — Splash Tags. These are ColdFusion custom tags that extend ColdFusion and HTML to work with Splash. Here’s a simple example: the <s:title /> tag. This tag just retrieves the page’s title from the page object and inserts it in place of the tag. So, in your layout, you would typically have something like:

<title><s:title /></title>

The pages title information from the database is then easily inserted into the HTML title tag!

There are a lot more tags, so see the Wiki.

Splash in Action

I recently completed the DonorUp.com website using Splash. I was really pleased with how easily I was able to get many thing to come together. So, try Splash and leave a comment to let me know how you like it!

Clarke Bishop CFWheels, ColdFusion, Splash CMS , ,

Learning CFWheels — Debugging

February 24th, 2010

CFWheels has some great documentation and examples, but there is still a small learning curve. As you are getting going, it helps to have a few debugging tips. So, keep reading …

On the CFWheels Google Group, Cathy recently asked about the sendEmail() function. This is a pretty good example to show you some debugging tips.

sendEmail() wraps the cfmail tag. Here’s some more information:

CFWheels on sending email.

This all looks pretty straightforward, but what do you do if it’s not working?

First, setup a test view page. Go to the Wheels views folder and add a new folder called test. Then create a new file called index.cfm in the test folder. The path should be /views/test/index.cfm.

In the index.cfm file you just create, put the following:

1
2
3
4
5
6
<cfset
  set(functionName="sendEmail",
  server="yourServer",
  username="yourUsername",
  password="yourPassword")
>

This will trigger the sendEmail() function. You can access the test page at http://localhost/index.cfm/test. But, if you go to this page, you’ll get an error because we didn’t create myemailtemplate, yet. So, make another CFM page in /views/test/ called myemailtemplate.cfm. The content can be anything you want. Something like “Test email” is fine.

Wheels knows you are in the Test controller, so it looks for templates in the /views/test folder. Wait a minute! You never said anything about creating a controller. That’s one of the cool things about Wheels. Even without a controller, it will still show you the view page, and things still work!

Now, go back to the test page at http://localhost/index.cfm/test. If everything is working, you should get an email message. If it’s not working, you can put other stuff in your test page. Try these out:

  • <cfdump var=”#params#”> will show you the params structure with your actions, controller, data you’re passing, etc.
  • <cfdump var=”#wheels#”> will show information on your filters.
  • <cfdump var=”#application.wheels#”> will show all the wheels settings, functions, routes — All kinds of cool things.

Now sendEmail() is a little trickier. It uses ColdFusion’s <cfmail> tag. Put this in your /views/test/index.cfm file:

1
2
3
4
5
<cfmail from="me@mydomain.com"
   to="me@mydomain.com"
   subject="Test Message">
  This is a test
</cfmail>

If this won’t work, then it’s your server configuration, not Wheels. You may have to specify your server name or login information. That’s pretty easy, too. Just put the following in your config/settings:

1
2
3
4
5
6
<cfset
  set(functionName="sendEmail",
  server="yourServer",
  username="yourUsername",
  password="yourPassword")
>

I hope this helps!

Clarke Bishop CFWheels, ColdFusion