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

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 <a href="<a href="http://api.freestylesystems.co.uk/api/function/views_get_all_views/6">views_get_all_views">http://api.freestylesystems.co.uk/api/function/views_get_all_views/6">vi...</a>()</a> 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 <a href="<a href="http://api.freestylesystems.co.uk/api/function/views_get_view/6">views_get_view">http://api.freestylesystems.co.uk/api/function/views_get_view/6">views_g...</a>()</a>. 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.