Building an ExpressionEngine Site - Chapter 05

Editing content, getting rid of RDF code, implementing a Miscellaneous Content weblog, and embedded variables.

This is the 5th chapter in the Building an ExpressionEngine Site Series.  In the previous installment we created a new weblog and field group to hold Home Page content. 

In this chapter we’ll do a few odds and ends - we’ll edit our content to get rid of the “greeking”, we’ll change some configuration settings on the new weblog to prevent EE from putting in Trackback-related code, and we’ll implement a Miscellaneous Content weblog to store the text found in the green area under the main navigation (and in the process, use one of the most powerful EE features available).

Editing Content
No, this isn’t a step necessary to getting this site up and running on EE.  At this point in the process, however, I’m ready to see some visual changes to the rendered page to show that it’s actually not the static HTML/CSS we started with.  So let’s do some quick content editing:  In the EE Control Panel:

  • Click the Edit tab
  • Either scan the list for your entries, or use the filtering and sorting controls that EE provides to find your entries.
  • Click the entry title to edit.
  • Change content to suit
  • Click Quick Save to save your changes but remain in Edit mode.
  • Click Update to save your changes and get a preview of them.
  • I’m going to change out the template graphic for one of the EE linking buttons, write a description of the project at hand, include some of the comments that people have so graciously left, and change the “Our Assets” section to “Helpful Links” with links to other EE sites.
  • Once your changes are saved, refresh the site in your browser.

There - now we have a home page some “real” content.  A small step, but it feels good. 

Except - now that I’m actually trying to read the page I’m seeing how small that text really is.  I edited the CSS to bump up the size of the text in the main content area from 8px to 10px.  I had to then size down the site title text, slogan text, the text in the green header area, and the footer - and I note this CSS has fonts specified in pixes, percentages and ems.  This is one of the not so fun parts of figuring out someone else’s code.  The sidebar content also seems to now visually compete a bit more with the main content, so maybe I’ll tweak that in a future installment - either make it a touch smaller again or a bit more greyed out.

RDF/Trackback Code
If you’ve looked at the HTML that ExpressionEngine is rendering since we implemented the weblog to hold the Home Page content, you’ve probably scratched your head and thought - what the heck is *that* stuff” (see the green code in the screenshot) ?

EE has a blogging heritage, and this is one of those places where it shows.  This code is for Trackback Autodiscovery.  I don’t want to get sidetracked with a big explaination of what Trackbacks are and how to use them—you can use Google for that as well as I can.  Trackbacks are most useful on a true weblog, and since that’s not what this page is let’s configure EE to not add this to our code.

This is a per-weblog setting with EE, and to change it we again go into the Control Panel:

  • Click the “Admin” tab.
  • Click “Weblog Administration”
  • Click “Weblog Management”
  • Choose your weblog, and click “Edit Preferences”.
  • Click “Trackback Preferences”
  • Set “Allow trackbacks in this weblog?” to “No”.
  • Set “Add Trackback Auto-discovery code to your pages?” to “No”
  • Click “Update and Finished”
  • Refresh your Index page in the browser, then view the source HTML.  The RDF code should be gone.

Miscellaneous Content Weblog
So this template has these sorta-cool, but sorta-odd paragraphs of text next to the search box.  It’s hard to know the designer’s intent here - was that text supposed to stay the same throughout the site, be specific to each section, or be completely randomized and independent?

I know I don’t want just one blurb there over the whole site, so that’s out.  Randomized client testimonials would be cool - but the way this text is positioned over the green that includes the main navigation it just feels like there should also be a semantic relationship between them.  So we’ll need six little blurbs of text, and a way to relate them to the selected main nav.  And these blurbs of text should be editable like any other content on the page.  To be editable they’ll need to be in weblog entries - but stuffing them into our existing Home Page weblog doesn’t make sense either as these will appear in other sections of the site.

One perfectly valid option for implementing these would be creating a dedicated weblog for them.  However, if you look past these blurbs you’ll see other little “chunks” of content that should be editable—the site footer text, the “no results found” message that comes up on empty searches, the confirmation message that appears after submitting the Contact Us form, etc.

What I’ve gotten in the habit of doing on each EE site I work on is implementing a “Miscellaneous Content” weblog whose sole purpose is to hold all these little chunks of content that I want clients to be able to edit.  This has proven to be a handy little tool for making the entire site client-maintainable.

So for these chunks of text we need to

  • Create a new weblog
  • Assign the existing simple_content” field group
  • Publish an entry into the new weblog
  • Modifying EE templates to pull in the new content

The Easy Stuff
We covered the specific steps for creating a new weblog in Chapter 3, so I’m not going to repeat them here.  Essentially I’m going to:

  • Create a new weblog with the full name of “Building Series Miscellaneous Content” and the Short Name of “bees_misc_content”.
  • Edit the preferences to turn off the Trackback code as per the above steps.
  • Under the “Edit Groups” option for the weblog, make sure it’s set to the existing “simple_content” field group.
  • Publish a new entry to the new weblog, with a title of “Home Page” and a url title of “home-page”. Note - the url title will be critical in the following steps

Modifying the Embedded Template
Now for the fun stuff—I’m going to introduce you to one of the most powerful features of ExpressionEngine - embedded variables with embedded templates.  Here’s why:  In Chapter 2 we “chunked up” the static HTML template and now we have an embedded template that holds both the search box and these section-overview paragraphs of text to the left of the search box.  You can view the rendered versions of just that template here, and do a view/source to see the static HTML we pulled out of the initial template.

But wait—now we want the promotional text to change depending on what section of the site we’re in.  In other words—we have a common, shared template that needs to adapt itself to the section of the site it’s being pulled into.  You might be tempted to un-embed it, and stick it back in the parent templates so that it can be section-specific. That would work, but wouldn’t be nearly as fun.

As we implement the other sections of the site and publish new entries in the Miscellaneous Content weblog to go with them, all the embedded template will need to know in order to be adaptable is which entry to pull for which section.  We can tell the embedded template which entry to pull by passing a value to it from the parent template, then using that passed-in value in the weblog:entries tag in the embedded template.  I’m going to use the url_title as my embedded variable - you could also use entry_id, but the url_title is more readable.

This concept may be a bit confusing - but I think looking at the code will actually make it clearer.  We need to modify two templates - the parent index template, and the “search_section_intros” embedded template.

Modifying the Parent Template
Not a huge change here—on the line where we are embedding the “search_section_intros” template we need to add the variable name and value that we want to pass to the embedded template.  The code is currently:

{embed="building_series_ch5_embeds/search_section_intros"}

and it needs to change to:

{embed="building_series_ch5_embeds/search_section_intros" the_url_title="home-page"}

So my variable name is “the_url_title”, and the value is “home-page”.  I got this value by grabbing the URL title that EE assigned my new “Home Page” entry in the new Miscellaneous Content weblog.

Note - again if you are following along with this series you’ll need to edit the name of the embedded template group as I’m creating a new template group for each installment of the series.

Here is a text version of the modified Index template:chapter_5_index.txt.

Modifying the Embedded Template
We’ve got the parent template “sending” the URL title of the entry we want the embedded template to pull.  Now we need to code the embedded template to use that variable in a weblog:entries tag to pull the right content.  I think this will be easier if you take a look at the text version of the template and we can work through what’s going on: chapter_5_search_section_intros.txt.

Looking at embedded template:

  • You’ll note that the search box is left unchanged - we’ll deal with that in the future.  For now, just look at the “lside” div.
  • We use another weblog:entries tag, this one pulling content from the new “bees_misc_content” weblog
  • We use the limit="1" parameter to ensure that we’re only grabbing one entry.  We don’t want multiples in this case.
  • The next parameter - dynamic="off" is important (and the biggest source of posts in the EE forums).  Please reference the EE Docs around this parameter.  Since we’re not wanting the page URL to affect which content we pull from the new Miscellaneous Content weblog, we need to turn it off.
  • The next “disable” parameters are again for performance reasons.  It’s just a good habit to get into specifying them with every weblog entries tag you write.
  • Here’s the meat of this step - where we use the url_title parameter to specify what entry we want to pull, but instead of hardcoding a value we insert the variable {embed:the_url_title} between the quotes.  This way the weblog:entries tag will use the url title that we specified in the parent template - and with each new parent template we just change out the value of that variable.  The code here in the embedded template will not have to change.

And the results?  Here’s the rendered version of the site, with our new content, no Trackback code, and new section-specific intro paragraph.

What’s next?  We’ll add the footer text to the Miscellaneous Content weblog, then I think we’re ready to move on to implementing the About section.  Note that I will need to skip a week in this series, so the next chapter will be published on or around September 14.

On to Chapter 6.
Back to Chapter 4.

Learn ExpressionEngine® Fast

Visit Train-ee.com for the latest in ExpressionEngine training designed with one goal in mind - to get you up to speed on ExpressionEngine® as quickly as possible.

The latest Train-ee Products:

The latest from the Train-ee blog:

Comments

1

September 05, 2007

I must say, Excellent work!  Nice series, and one I wish I’d had a while ago. 

Some neat tricks with the url_title parameter as well--hadn’t thought of using it that way, or the miscellaneous weblog.  I’ll have to include that one!

2
Chuck
September 26, 2007

first off - thank you so much for this. i’ve heard awesome things about EE and this truly is the easiest time i’ve ever had with customizing a CMS. your documentation is the perfect introduction!

however…

one thing that isn’t working (at least for me) as described above. you’ve created the URL Title as “home-page”, however when i save it, its saved automatically as “home_page”.

you mentioned that the title is critical in the next steps, so maybe i’ll see something later on, but is there a setting i’ve missed?

thanks again,
chuck

3
Chuck
September 26, 2007

yep, i knew it… as soon as i got to chapter 6, there was the explanation…

in case anyone needs it for this chapter, the setting is here: Admin > Weblog Administration > Global Weblog Preferences > Word Separator for URL Titles

-chuck

4
Dan Diemer
November 16, 2007

Thanks Michael for the great introduction, and thanks Chuck for posting that tip. Fixed my problem.

5
(Author)
January 15, 2008

FYI:  The Building an ExpressionEngine Site series is now available for purchase as an eBook on the newly-launched Train-ee.com.

6

February 06, 2008

What exactly is in the ‘building_series_ch5_embeds/search_section_intros’ embed? I am having trouble pulling the ‘home-page’ post into the header.

In site index:
<div id="header">
{embed="embeds/main_header"}
{embed="embeds/main_subheader" the_url_title="home-page"}
{embed="embeds/main_nav"}
</div>

My subheader is equivalent to your search box. I don’t really know what goes inside of it. If you’re giving it a URL to pull from, does it even need anything? How is the_url_title being used?

7

February 06, 2008

Never mind. I see it. I really don’t know how I missed the entire last section of this chapter.

8
Johny
February 13, 2008

I’ve never heard of ExpressionEngine before, is it secure?

9
(Author)
February 13, 2008

Hi Johny - That’s really a question best asked in the forums at http://www.expressionengine.com—but short, yes.

10
Ron
March 17, 2008

Much more than more fun ...

“You might be tempted to un-embed it, and stick it back in the parent templates so that it can be section-specific. That would work, but wouldn’t be nearly as fun.”

... For me ... the business reason to make section specific information an “entry” in EE is so that your client who may want to update that section information won’t have to be coder to do it ... It’s a great way to help your client succeed.

Thanks for this by the way ... it’s a huge help

11
(Author)
March 17, 2008

Ron - you miss the point.  My approach allows client update while still being embedded/centralized from a code perspective.

My goal with EE sites is that all text that shows in the browser is client-editable.

12

April 26, 2008

Perhaps I’m just totally dumb, but I haven’t gotten this to work. I can verify that the chunked out search section is indeed embedding properly, as I have written some text that seems to appear on the front page. The search box also appears.

I’ve made my new weblog have the exact same name as yours and have created a new entry in that weblog titled “Home Page” and named “home-page”..

To my understanding, we basically just want this little section of text to change based on which page we are on? How is this, in anyway dynamic? Forgive me, I’m just having trouble understanding the fundamental concept behind this. On the index, you have linked to the page and have assigned the url to the embed which points itself to the “home-page” we created as an entry in the miscellaneous weblog.

If we are on another page of the site, how would this somehow magically appear if it is always pointing to that file anyway?

I know I’m missing some fundamental concept here. Perhaps I’m just more confused because I can’t get this to work at all.

Any help is appreciated. =)

13

April 26, 2008

I’ve figured this out. I’m not sure if this is anything new, but incase you were wondering why I couldn’t get it working with following your instructions to spec, I’ll tell you: When I defined the URL as “home-page”, it had defaulted to actually rename itself to “home_page”. Subtle difference, but of course, the underscore changes everything!

Just to let anyone else know, I am running version 1.63. I don’t know if this is a normal behavior or something I can adjust, but it’s working now.

I still am having difficulty understanding the concept though. How can this text change if it’s only pointing to that one extra file for every other page that is to be created? Or for this purpose, is this not suppose to change for every page, but rather serve as some type of semi-permanent slogan that can be altered conveniently through a weblog entry for future purposes?

My regards!

Name:
Email:
URL:
Comments:

Remember me?

Shoot me an email when someone responds?

Enter this word:

Here:

GetBoyinked

Subscribe to Boyink.com