ExpressionEngine, Tutorials

Give Your Client More Control by Utilizing a Single-Entry Structural Channel

November 9, 2009
by Ryan Masuga

Make use of a “structural” weblog/channel that contains only one entry, where each custom field controls some aspect of the site. Then give your users easy access to these controls by linking directly to the entry from a link at the top of your control panel.

What's the Point of this?

There are times when you want to give your client control of entry ordering in certain areas, or whether or not blocks of content show up, among other things. Wouldn't it be nice to collect all these "control" fields and switches in one place? The idea is to utilize a single entry in a channel dedicated to these controls to do so. For every area or item you need to control, you create a new field, rather than a new entry. Depending on your sites' complexity you may end up with fifteen fields here, or you may only need three.

You're probably thinking that a lot of this could be done with Fresh Variables. Some of it could be, but you don't get the power, variety, or flexibility of all the custom field types available to the weblog module. With a dedicated channel you have access to the full range of custom field types. Most common fields that I've used for control are Playa or FF Matrix (see Fieldframe) (primarily due to their ability to set custom orders, which clients always seem to need at some point) as well as basic "yes/no" dropdowns and checkboxes.

I feel that a control area like this should not live in a channel, so we'll do what we can to make it feel like it's not a channel. A better idea would be a separate control panel area like the Selected Items module (that add-on is limited to making ordered lists), but this tutorial deals with what we can do here and now.

If anyone wants to talk about making a new add-on that is somewhere between the weblog module and Fresh Variables, please get in touch with me.

In an effort to prepare myself for the upcoming EE 2.0 release, I'll refer to weblogs as "channels" in this article (or do my best…I've been using the term "weblog" going on four years now). Also, I've always referred to a single-entry channel like this as a "structural" channel, although there has since been an add-on developed (which many of you are familiar with) called Structure. I'll continue to call it a "Structural" channel here out of habit, but you can refer to it as anything you want.

Making the Channel and Its Lone Entry

Make the channel like you would any other, and make a custom field group to go with it. We then want to create only one entry in this channel. For this channel's one entry we create as many custom fields as needed. We then hide this channel from showing in the Publish or Edit Menu flyouts (Edit Menu is a useful 3rd party extension that creates a flyout menu underneath the Edit tab exactly like the one under the Publish Tab) so no new entries are made to this channel. We can use extensions like Hidden Weblogs or Publishers Clearinghouse to hide selected channels from these menus. You can still access the channel if you either click on the Publish Tab or use filters on the Edit screen, but out of sight can help keep it out of mind.

Add a link directly to this channel entry

If you're like me, you already have too many tabs across the top of your control panels, and it's not the easiest thing to link directly to an entry from them. The thing to do is to add a new row of nav to the top of your control panel with LG Add Sitename. At its simplest, LG Add Sitename adds the name of the site to the top of the control panel (just like MD Add Sitename did before it) but it brings a lot more options with it. As of version 1.3.0, a setting called CP <body> additions allows you to add whatever you want just inside the body of the Control Panel, and that's where we'll enter the markup for our new navigation, which will include the link to our Structural/Control entry. Here is some sample code that will add a new (small) UL to the upper right corner. This will let you add links to your heart's content:

<div id="supermenu">
<ul>
<li><a href="index.php?S=0&C=edit&M=edit_entry&weblog_id=10&entry_id=123">
Edit Homepage Structure</a></li>
</ul>
</div>

So, we've created a new UL called "supermenu" with a single link to entry 123, which is in weblog/channel 10, where I'm housing the custom fields that will let the user control aspects of the homepage. I copied the direct link to the entry from the browser's location field when I was on the entry.

Style the New Navigation

Next we'll need to style the UL. I decided to add the CSS to the top of the default.css file for the (default) control panel theme, located at /themes/cp_themes/default/default.css If you're using the default theme, you will have to remember to not overwrite this file if you upgrade your EE installation. You could add this CSS right inside the textarea for the LG Add Sitename CP <body> additions setting instead, if you prefer. The CSS I used is:

#supermenu {background: #222E36;text-align:right;padding: 0px;width: 100%;display: block;}
#supermenu ul {padding: 3px 30px 3px 0;margin: 0;}
#supermenu ul li {display: inline;font-size: 10px;padding-left: 10px;}
SupermenuSample Supermenu with three links

The resulting menu is small, out of the way, and fits in with the rest of the control panel.

Real Example

What is a scenario in which I would want to use a "Structural" channel? One of my clients needed a lot of control over their homepage. I set up default behaviors (for example, selecting the eight most recent features in descending order), but they wanted to be able to override every area of the homepage whenever they wished so they could manually select the articles to display, and order them however they wanted (you know you've heard a similar request at some point, right?). They also wanted to control whether entire chunks of the homepage even showed up at all.

Structural Entry SampleSample Structural entry (Simplified here for display)

For this client I set up a structural channel with one entry, and populated it with a mix of Playa fields, FF Matrix fields, yes/no dropdowns, checkboxes, and basic text inputs. They might override an entire section by setting a drop down to "yes" in order to activate the override, which will then pull info from the Playa or FF Matrix field. The text inputs are used to override the default titles in different areas of the homepage. Checkboxes are also used to toggle things on or off.

Make it Happen With Embeds

In order for their controls to work, you'll first have to query your structural entry as to what you're going to do, and then you use embeds to build the template. Here is a simple example:

{exp:weblog:entries weblog="structural"    
   disable="categories|category_fields|member_data|pagination|trackbacks" 
   dynamic="off" entry_id="123"}
    {if enable_tags == "y"}
      <h3>Tags</h3>
        {embed="sidebar/_tags"}
    {/if}
{/exp:weblog:entries}

You need to use embeds in many cases because you can't nest weblog:entries tags on the same template. This can be a bit of a performance hit, so make sure for the "structural" entries query to disable anything you're not using with the disable parameter in the weblog:entries tag! In the simple example, we check to see if we want to show the tags, and if so, embed the template that contains the tags.

That's all there is to it. My client can either let their homepage do what it is supposed to do by default, or override all of the areas to pull in manually selected content (for example, if they wanted every article on the homepage to have a theme). I've shown you a simple example here, but there are much more complex things you can do. ExpressionEngine 2.0 is around the corner and may have different ways of approaching this, but I've found this method very useful for EE sites running 1.6.

17 Comments:

Derek Hogue 11.09.09

I love this idea for adding an additional level of configuration for clients.

One suggestion: the Custom CP Home Panels extension (shameful plug) might be put to good use in adding this configuration link – along with other bits of important info (like links to mailing list management elsewhere, etc.)

Nelly 11.09.09

Great article! I might use this idea for a site I’m developing right now. Combined with Derek’s add-on this will make my clients’ work easier.

Jason Morehead 11.09.09

I’ve done something similar to this on a couple of sites, though not quite to the extent as indicated in this article, and it works really well.

Andy Marshall 11.09.09

Presumably as you cant call a value set in this Structural entry inside another set of weblog tags, you cant use it to fine control how a set of entries are displayed, eg add an additional one in there – it’s either / or…

There was an add-on that loads all values from an entry into a template up front to avoid several queries of the same entry across a template – can’t remember it’s name, but it might help reduce load when checking these values in a template, esp a home page that might already be calling lots of different weblogs / channels.

Andy Marshall 11.09.09

Very interesting article tho! Will be looking to use something like this in an upcoming site that has a lot of diffeent content and quite a fine level of layout control – thanks!!

jwmatlock 11.10.09

jwmatlock

This is why I love ExpressionEngine. Thanks for the article and giving me another way to think about building things.

Karl Bowers 11.10.09

Karl Bowers

Excellent stuff! This is a good technique I can employ on a current client project. Many thanks for this :-)

Bjørn Børresen 11.10.09

nice hacking :-)

.. but what you really want is a customizable config module? It would be better to have them as global variables as well, since I can imagine the config variables will be scattered all over the place and it will be challanging to have a {exp:weblog} tag around everything ..

mahalie 11.10.09

I think this could come in really handy for smaller sites where there’s an about page and a couple other places where you need to use custom templates and you want clients to be able to edit part of the page and reorder subpages/links.

Of course it would be ideal if this were a custom tab and you could abstract settings that are meant to be global from a weblog, er, channel entry.

ErikReagan 11.11.09

Nice article Ryan. I’ve done something similar but nothing to this extent.

@bjornbjorn

You’re right in saying that a Module would better serve something like this, however module creation is out of the reach of many people who build sites in ExpressionEngine. I think this is a great solution for those who aren’t quite ready to dive into Add-On development

AdamG 11.12.09

AdamG

This is a great article Ryan – I like your ideas; it’s something many developers think about I’m sure. I wrote a similar forum post on this recently: Code logic for display of related data

Other content management systems I have worked with have this management built in – for example Zope /Plone. It would be great if EE had something similar. Using channels is very flexible but has implications for performance. BTW, in your example, you don’t need to disable category_fields if you disable categories – they’re disabled automatically.

amystoddard 11.13.09

Great post.  I’m building a site right now using the http://buildwithstructure.com module for static content, but I’ve got non-static channels built too.  I could see using this approach in addition to the Structure module.

Erwin Heiser 11.16.09

Nice article, this is definitely an interesting approach… though sometimes giving the clients less control is an even better option :)

lebisol 12.22.09

Very nice tip, I have used this approach to build a control handles over ‘contact us’ form where user can decide what is shown on the page.

Also, it would be a lot easier to just create a new tab while editing the entry rather than hacking up CP or using more plug-ins.

Thanks for sharing!

Ryan Masuga 12.22.09

Ryan Masuga

This may no longer be a method I use because Low released an add-on recently called Low Variables, which looks like a very nice blend of custom field types (that can be parsed early) that do not live in the weblog/channel area.

Low Variables looks very promising, and appears to solve what I was trying to achieve in this article. However, if you’re on a budget and can’t swing the cost of Low Variables, the method outlined here should still work for you.

hungrysquirrel 01.04.10

This is a fantastic idea and approach especially for the designer types that are not able to solve these types of customizations with their skill sets. Great ideas for the new year :)

You must be registered member to comment. If you're already a member, log in now, and if not go register (it's free and easy!).