Archive for the ‘Drupal’ Category

When is a view not a view? When it’s a page

Colin Calnan | Monday, December 8th, 2008

We’ve come across an issue quite a few times during the development/build of a site where a client wants to include some content above or below a view and wants to have the ability to edit that content. There are a number of ways to achieve this functionality:

  1. You could simply use the “Header” field in the create/edit view screen and place some text in there. However, that does not have a nice WYSIWYG editor, one could be assigned but it’s not ideal.
  2. You could create a block and place it in a region above the view. Again, unless you have a WYSIWYG Editor set up for blocks, this is not perfect.
  3. You could, in some way, add a view to the bottom of a page - ah!, that’s it.

The caveat with 1 and 2 above is that it requires giving the site editor/client access to views and blocks, in a lot of cases this is way too much control and will usually result in problems. 3 is the ideal solution. Once I figured this out, I began to develop the functionality: I created a Select CCK select field for all page content types which pulled a list of all available views by using the views_get_all_views() function. This field stored the name of the view, I then used the name of this view in page.tpl.php to load the view via the function views_get_view(). It started to get a little messy, so I decided to start building a module, only to find that one already existed.

It’s called Viewfield and does exactly what it says on the tin. It allows you to add a CCK field which is a list of views to choose from. The view will then display on a page in whatever position and format you choose. It works great.

You can see it in action on this page from the BCNDP website.

Search Engine Friendly URL’s and Drupal - Part 2

Colin Calnan | Wednesday, December 3rd, 2008

In my previous post I showed you how to set the friendly URL for each page/piece of content on your site. Hand curating can be fun, but it’s also time consuming and requires a little thought. It can also be a little cumbersome when you have a long title, like the title of this post. In steps the Path Auto module to save the day. In conjunction with the Token module, Path Auto automates the task of creating and setting these URL’s. How does it work? It’s pretty simple really.

  • Using Drupals internal URL alias functionality, Path Auto automatically(automagically) creates URLs for you when you create a new piece of content.
  • The structure of this URL is determined by you, the user, via the Path Auto administration page (http://www.yoursite.com/admin/settings/pathauto).
  • Each individual content type (via CCK module) can have it’s own settings
  • The path can be hard coded to anything you like, or it can use “tokens” to determine how the page is made up, for instance:
    • The path can be made up of the title of the content (http://www.example.com/the-title-of-the-content)
    • The path can be made up of CCK types and CCK fields (http://www.example.com/albums/rock)
    • The path can be made up of vocabularies and taxonomy terms (http://www.example.com/2008/10)
    • The name of the author (http://www.example.com/colin/drupal-search-friendly-url)
    • There is a comprehensive list of the options (replacement patterns) available for creating URLs /aliases on the path auto settings page, some examples:
      • [nid] - Node Id
      • [title-raw] - Unfiltered node title
      • [yyyy]- Node creation year (four digit)
      • [term] - Name of top taxonomy term
      • [author-name] - Node author’s user name
  • Once your paths have been setup you can then select the “Bulk generate aliases for nodes that are not aliased” for those paths you have configured. This will create new URLs/aliases for your existing content. Also note that this will generate aliases for all existing nodes which do not already have aliases.
  • In the future, when creating new pieces of content, the URL/alias will be created for you based on the criteria you have chosen in the path auto settings.

So that’s it, not that difficult really. There are a few issues I’m come across when using path auto, and my one piece of advice is to decide on your alias structure before you start entering content. Or, if you have entered content and are running a bulk update, Think carefully about your alias structure. If you do mess it up there’s an easy way to re-run the alias update. You can do this via Update area of the “Content” management page. Select the content you want to update and choose “Update path alias” from the drop down options.

Welcome Back, Chris!

Lauren Bacon | Friday, October 24th, 2008

Re-reading the title for this post, the theme song for Welcome Back, Kotter pops unbidden into my head. In some ways maybe it’s an appropriate reference, because we have brought back to the fold a smart, beloved, and drily witty colleague, Chris Torgalson, after a year-long stint at grad school in Belgium. (That being said, the parallels pretty much end there… certainly none of us are about to ‘fess up to being Sweathogs.)

Chris was our first-ever hire at Raised Eyebrow, taking over the coding reins from me, and during his time here he helped put us on the map for open-source CMS development. He has experience with several open-source CMS options including Drupal (our CMS of choice for most projects) and Typo3, a lesser-known but highly robust CMS used by several of our clients.

We are incredibly excited to have Chris back at Raised Eyebrow; he and Colin are already working on streamlining some of our Drupal development processes, and it is evident that two intelligent, focused, technical problem-solving heads are indeed better (or at least faster) than one. I look forward to seeing what these two can accomplish together in the coming months!

Search Engine Friendly URL’s and Drupal - Part 1

Colin Calnan | Thursday, August 28th, 2008

Content management systems (CMS) allow you to create content on the fly without having to worry about coding in HTML or uploading via FTP. Most content management systems then use a combination of PHP or ASP querystrings to deliver that content in a format something like http://www.yourdomain.tld?pid=36 or http://www.yourdomain.tld?q=node/15.

The reason for this is mostly to do with the database driven nature of a CMS, and it’s ability to retrieve all content/data related to a specific id. So what’s wrong with that? Most search engines don’t index pages whose URL contains a question mark or other character (like an ampersand ‘&’ or equals sign ’=’).

What does this mean? It means that people can’t find your site. There are times however when you will want to create a nice clean URL for use in a marketing campaign or as a link on Facebook, or some other link sharing website. There are a number of ways to achieve this using Drupal and I’ll examine each of them in turn. Today we’re going to hand curate (Emiras favourite term) them.

Hand Curated

The quickest and easiest way to create a nice URL is to do it when you’re creating new content. Scroll down to the “URL Path Settings” area and simply enter your path. Remember to leave out the trailing slash at the end, otherwise it won’t work, it’ll be banjaxed.

While this path can be anything you want, try to keep to the following rules:

  1. Keep it short - no one will remember a really long URL.
  2. Keep it simple - we’re not trying to win the Man Booker Prize here.
  3. Keep it relevant - the URL should relate to the title of the page/article and it’s content - search engines take relevancy into account too when indexing your pages.
  4. Keep it organized - if you have a few different types of content on your site, try to organize your content via the URL. For example all Articles would go under “articles/your-title-here” and all Publications would go under “publications/your-title-here”. Also note that I use the hyphen “-” to separate the words in the title. You can use the underscore also “_”, but I prefer the hyphen as it’s easier to read aloud and people refer to it as “dash” also. You’d be surprised how many people I speak to don’t know what “underscore” or “underbar” means.

In Part 2 I’ll examine using the Path Auto module to automate this for you and then for Part 3 I’ll go on to talk about using Views and Arguments and how they can be used to create what are called “Hackable URL’s”.

 


t. 604.684.2498 | f. 604.685.5786 | e. turningheads [at] raisedeyebrow.com