Dreamweaver: Mass Detach from Template
September 27, 2006
Dreamweaver | Web Building
There are times when you may find it necessary to detach hundreds of pages from their Dreamweaver templates. Unfortunately, within the Dreamweaver interface the only way to detach multiple files from their templates is to open each one, then select "Modify:Templates:Detach from Template" from the menu. A better way to go is to use a simple "grep" search in BBEdit:
  1. Make sure you have a backup of your site. You can cause truly spectacular destruction with mass search and replace! OK, you've been warned!
  2. Open BBEdit, and select Find from the Search menu. The Find & Replace dialog will appear. (click to enlarge)


  3. Ads by Google

    Posted by ellen at September 27, 2006 04:30 PM
  4. Check "Use Grep" When you do this, you will notice it colors the grep wildcard characters red.
  5. paste this text into the Find box:
    <!-- #BeginTemplate.+? -->  
    
    Leave the Replace With box blank (you want to replace the Begin Template tag with a blank).
  6. Check the box for Multi-File Search, and Batch Find, then select select the folder on your local drive where the files reside.
  7. Click "Replace All." If you are the cautious type, and want to test it first, just click "Find" a couple of times, so that it will find the first result or two, and make sure it is highlighting the right tags.
  8. repeat using
    <!-- #BeginEditable.+? -->
    
  9. Now uncheck Use Grep because the next two are standard exact match searches (no wildcards needed)
  10. then repeat the search and replace using
    <!-- #EndEditable -->
    
    and then
    <!-- #EndTemplate -->
    
    That's it - your files are now clean of template tags!
    Ads by Google

4 Comments

It's amazing to me that DW doesn't allow for batch detachment. Thanks for confirming that for me. I had already done the grep replace mentioned below when I thought, "there must be a way to do this from Dreamweaver." Nope. I guess not.

Anyway, here's an improvement to your grep that doesn't require four separate searches. You can do it all with one, single grep search and replace like this:

\s*<!-- (#|instance)(begin|end)[^>]+-->

The \s* at the beginning will get rid of the blank line "hole" in your source code that would be left by deleting just the comment.

The '#' is actually 'instance' in my version of Dreamweaver (v8). I've made that an alternation grep.

All DWT comments immediately follow the above pattern with either "begin" or "end" (thus the alteration of "(begin|end)") for the extra check of accuracy.

There should be no ">" characters in there until the end of the comment tag, thus why my grep can is simplified to essentially say "any character but '>'" and then ending it will "-->" for the close comment.

I've tried this and it worked excellently to delete all of the template comments from files with one search and replace.

Is there a way to do this in windows? I don't have access to a mac and thus bbedit. I tried exectuing the following in cygwin to no avail:

grep \s*]+--> contact.html

I have Aptana installed and I use it time to time. I know it works as a plugin to eclipse but can I do the same thing there?

Also, is grep and regular expression the same thing?


Ads by Google

 RSS   |   Contact Me


Ads by Google