Advocacy

  Myths
  Press

Dojo (HowTo)

  General
  Hack
  Hardware
  Interface
  Software

Reference

  Standards
  People
  Forensics

Markets

  Web

Museum

  CodeNames
  Easter Eggs
  History
  Innovation
  Sightings

News

  Opinion

Other

  Martial Arts
  ITIL
  Thought


Metatags
What every Webmaster should know about HTML

By:David K. Every
©Copyright 1999


Meta- (prefix) means: altered, changed, derivative, more comprehensive, above and beyond -- and so on.

Tags are commands for HTML to tell the parser (browser) what to do, and how to format (display) your page.

What am I talking about?

Metatags are a very simple concept -- they are just custom comment tags in HTML, that you use to extend HTML.


In html there is THE meta tag (defined in your HTML page, at the top) --
<META NAME="keywords" CONTENT="good, bad, indifferent">

What this does is help search engines to figure out what you page is about. People refer to the parameters as meta-data.

This is not what I am going to write about. This "meta" tag, is not nearly as important a concept as other forms of metatags (but it is still important). Some people use the term metatags as I do (and I am sure there are other names for metatags as I mean them, like supertags, or custom-tags). Pedantically, the metatags I am talking about are just that -- "altered-comment-tags".

Be careful when using the term metatags (either way), since people will often assume you are talking about the other form of metatags.


In HTML anything put inside of <!-- HERE --> is a comment. That means that browsers will not display the tag, and it will basically be ignored. "So what is the big deal?", you say. Well, just because browsers ignore them does not mean that you should.

HTML formatting (tags) are not always clean and clear. It would have been great if HTML Documents were two separate streams or files -- one for the text (body), and a file bound to that which had all the formatting for that text. Think of the possibilities -- you could change the style without effecting the content, the text (content) would be readable by lay-people, and so on. This concept has been done in computers for many other things (the Mac does something like this with its data / resource fork, and so on), and is so versatile and clean that it couldn't possibly be used (that would mean that someone was thinking ahead). This is basically what WC3 is trying to do NOW with CSS (Cascading Style Sheets), a decade late -- but CSS doesn't work with all browsers (and won't for years), and isn't exactly fully implemented. So all of us webmasters are still left with the problems today.

What we have is formatting and text information in the same stream (file) that looks something like this;

<formatting>
<formatting>
text
<formatting>
text
text
<formatting>

And so on....

If the formatting is messed up in one part of the stream, it generally screws everything up for quite some time (or until the end of the document). Bleck.

Well enough ranting. The point is that we webmasters want to separate the formatting from the content -- so that we can globally alter the formatting for our entire site. Well with metatags, we can do the next best thing. Imagine this;

<!-- start Metatag1 -->
<formatting>
<!-- end Metatag1 -->
text
<!-- Metatag2 -->
text
text
<formatting>

What does that give us?

Search and Replace (RangeTags)

There are many search and replace tools that can replace from the end of one item, until the start of another item. So if I have created all my pages to have metatags, I can tell them to replace everything between <!-- start Metatag1 --> and <!-- end Metatag1 -->. Or in other words, I can completely replace that formatting, without effecting the body text. The metatags would give me (the webmaster) a way to separate the streams -- the body from the formatting.

Now on a page by page basis that is cool -- but there are many tools that can also replace things in a series of Documents as well. So they can do replacement not just on a single page, but on your whole site at once.

BBedit can do a GREP search on a directory (web site, or part of one), using a search string like -- <!-- start Metatag1 -->[^*]+<!-- end Metatag1 -->

CodeWarrior can also do GREP searching, and makes an amazingly good site management (search and replace) tool.

HTML Grinder can "Replace Tagged Text" (or replace everything between two tags in a series of files), and is simpler and more focused (1)

TexEdit can do replaces on a single file, with easier wildcarding than GREP (1), but it only works on single files (not directories). So you have to script multi-file search and replace.

(1) I prefer searches that don't require GREP, because GREP is an annoying syntax, that always takes a few tries to get right. But it is very powerful, so I often find myself cursing at it, and eventually getting it to work.

Some tools are even scriptable. So not only can you replace one part of the format at a time, but you can have the script replace multiple things on each pass, or make multiple passes. Meaning that with the press of one button (after writing a script), you can have your whole site updated -- all because you used Metatags.

What does all this do for you? Well, the first time you decide to change your format, and you have metatags in place, and you don't have to manually cut and paste your format into 50, 100 or 500 documents, you will be a metatag convert for life. They are a godsend! To quote Mr. Popiel, "Now how much would you pay? But wait, there's more".

TemplateTags

If you look at <!-- Metatag2 -->, there was nothing around it. It didn't have any formatting - why? Well, what if you created an AppleScript to do a simple search and replace (automatically). The script could open a source file, replace "<!-- Metatag2 -->" with the formatting information you want (say the contents of another file), and save in a destination directory. Viola. You have added formatting information to a file that didn't previously have any.

As a webmaster, you could give a file to you writers that is very a simple template like:

<!--Title-->
text
<!--Author-->
text
<!--Body-->
text
<!--Date-->
text

Writers would just add the information between the tags that you want. Easy for people who are not HTML savvy to do (something that even most writers can figure out). Then you "compile" the file (run it through your script), and presto -- it now has your format. If you change your format, you just recompile this article -- and presto again, you have a newly reformatted version of your file.

A simple AppleScript to do some of this (using BBedit) might be:
 
on open theSelectedItems   -- items dragged onto script-app
  set theList to (every file of theSelectedItems) as list
  repeat with this_file in theList
    tell application "BBEdit 4.0" -- or TexEdit?
      open this_file
  
      find "<!--Title-->"
      insert file {"Path:TitleFile"}
  
      find "<!--Author-->"
      insert file {"Path:AuthorFile"}
 
    ...
 
      save window 1
      close window 1
    end tell
  end repeat
end open
 
Be careful -- this script modifies the file(s) you drop into it. You might want to keep both the original and the "compiled" file. It also doesn't have all the little extras (like it can't iterate through folders dropped on it, and doesn't have any error checking). BBedit is also quirky opening files that are not of its "creator". But this script should give you a good start. I may make available some more full featured scripts later.

Conclusion

So there are quite a few things you can do with metatags. I created a few scripts to do both types of functionality -- and both saved me a lot of time over doing it manually.

Sites start small (and maintainable) -- but they grow quickly. It is a good idea to start using these metatags early in your process. Define the ones that make sense for your application.

The trick is to be religious about it! Use them in EVERY file (or you'll regret it later). In general, if you create a form with metatags (and have tools to replace the metatags with a format), or if you have metatags around your major format groups, then you will be able to alter your formatting in the future, far easier than if you don't use metatags. There is still a learn curve, and it causes a little more work early on. But learning the intricacies of a search and replace tool, or some scripting, is often far easier than fixing dozens or hundreds of files.

Most of the techniques discussed are used in Frontier (either automatically, or through your own additions) -- which is why many webmasters consider it such a great product. However, I am pretty harsh on bad interface, proprietary technology and large learning curves (Frontier has all of those) -- and more importantly, I am trying to teach how it is done, so that people understand the concepts. Knowing this, you should be able to understand and use Frontier (if you choose).

Books on GREP (Regular Expressions)


Created: 3/12/98
Updated: 11/09/02


Top of page

Top of Section

Home