Code snippets auto modification on several pages

Discuss general web development questions. Help others and get help from others.

Moderator: kfury77

Code snippets auto modification on several pages

Postby BertrandH » Sun Sep 07, 2008 8:42 pm

Hi,

I would like to be able to save a custom library for each project.

Let's consider I have 300 pages with the same footer. If I decide to make a change in the footer, it seems I will have to change it manually on 300 pages, which is time-wasting.

Some automation would be nice. It would really ease my work.

I am new to WeBuilder 2008 and haven't found anything close to my request. If I add code from the library, and then change the code in the library, it doesn't apply the change on webpages containing the modified snippet.

Maybe, I missed something.?

Thanks!

Bertrand
BertrandH
 
Posts: 11
Joined: Sun Sep 07, 2008 8:36 pm

Re: Code snippets auto modification on several pages

Postby davenz » Sun Sep 07, 2008 10:37 pm

Hi Bertrand,

welcome to the forum.

I'm not sure exactly what you mean, but I'll take a chance; the library feature is just a repository for snippets of regularly-used code that you can refer to and use over and over again in your pages; it is not a CSS master library of used code that affects page content in any way. Having a different library, or set of snippets, for each individual site would be a reasonable feature request, but I don't think that's what you mean here. In WeBuilder you use items from the library in your code and that's it; they are not hot-linkied to your page at all.

In your situation, if you had 300 pages that need changing, there is not much you can do after the fact, though I would use WeBuilder's excellent find and replace features to make any site-wide changes. I have used tis before and it works very well.

Before the fact, you can design your site to utilise Master Pages or similar, where one 'master page' template controls the whole site, or, in a very similar vein, use a CSS-based layout template that you can change if you want the other pages in the site to look different (which is a kind of master page setup anyway).

Is this what you mean, or am I the one missing something?

Dave.
davenz
 

Re: Code snippets auto modification on several pages

Postby Cary » Sun Sep 07, 2008 10:42 pm

No, you haven't missed anything. The library of snippets are just that, snippets. They're not library items such as you would use with Dreamweaver. You should try using includes (SSI, PHP, etc.) to achieve this.

If you were using specialized software to get the same result and stopped maintaining a particular site, then whomever took over for you would either have to remake the pages or would need the same software you use. This is one of the major drawbacks to DW templates.
Cary
 
Posts: 82
Joined: Mon May 28, 2007 10:41 pm

Re: Code snippets auto modification on several pages

Postby BertrandH » Sun Sep 07, 2008 11:00 pm

Hi davenz and Cary,

Thanks for your replies.

Your master pages idea is closer to what I meant.... I understood library usage, only wanted to illustrate it didn't do what I was talking about. :wink:

My idea was this:
If I have a navigation bar styled with css. Each of my individual pages have list for 3 sections: home, links, contact me.
What if I decide to add a 4th section? Then, I would have to add a list item on my 300 pages (on each of the page).

davenz wrote:In your situation, if you had 300 pages that need changing, there is not much you can do after the fact, though I would use WeBuilder's excellent find and replace features to make any site-wide changes. I have used tis before and it works very well.


Do you mean, in this particular example, I could make a find & example of the complete list?
e.g.:
to find
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
and replace by
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>

Bertrand
BertrandH
 
Posts: 11
Joined: Sun Sep 07, 2008 8:36 pm

Re: Code snippets auto modification on several pages

Postby davenz » Mon Sep 08, 2008 3:36 am

Hi Bertrand

Yes, and I have used F&R to do exactly what your example does, that is, to replace a three-way button bar with a four way one. It works very well and forgoes having to hand-code everything. If you are paranoid about your 'replace code' overwriting anything else, then just use the 'find next' button and, if all looks good, then click 'replace'. Admittedly doing it this way for 300 pages would be a drag; I'd be more tempted to just go for broke and find and replace all, then fix anything that gets broken, which is not likely as the text you are replacing is pretty specific in the first place. Then there is always 'undo'/

Hope this makes sense.

@Cary

While I have used Dreamweaver long enough to know it wasnt for me (or my wallet), I didn't realise their Library feature did this 'template' type of thing. Thanks for making that clear.

Cheers guys

Dave.
davenz
 

Re: Code snippets auto modification on several pages

Postby NearZero » Mon Sep 08, 2008 6:42 am

Hi Bertrand,

I had posted, one post before yours a request for dynamic templates (masters if you like).

Use help in WB and look at the preprocessor commands, namely...

<!--%IncFile .\some_template.htm%-->
<---->

You can use this to update pages anytime you change your footer.

However, you must open each page and save it for the update to take place. It's safer then using F&R as you do not need to be concerned about exact pattern matching.

Sadly it's a time consuming process on big sites and the FILE | SAVE ALL does not work if you attempt to them in chunks.

Cheers
Steve
NearZero
 
Posts: 26
Joined: Mon Oct 08, 2007 1:52 pm

Re: Code snippets auto modification on several pages

Postby BertrandH » Mon Sep 08, 2008 10:19 am

davenz wrote:Yes, and I have used F&R to do exactly what your example does, that is, to replace a three-way button bar with a four way one. It works very well and forgoes having to hand-code everything. (...)

Hope this makes sense.

@Cary

While I have used Dreamweaver long enough to know it wasnt for me (or my wallet), I didn't realise their Library feature did this 'template' type of thing. Thanks for making that clear.

Cheers guys

Dave.


Yes, it makes sense. I hadn't thought about the F&R possibility. I am actually looking for an editor and was trying the trial version of WeBuilder2008. I came here to ask about my worry.

What made me thought about a feature like this is the library option in Dreamweaver. You understood it correctly. :wink:

NearZero wrote:I had posted, one post before yours a request for dynamic templates (masters if you like).

Use help in WB and look at the preprocessor commands, namely...

(...)

However, you must open each page and save it for the update to take place. It's safer then using F&R as you do not need to be concerned about exact pattern matching.

Sadly it's a time consuming process on big sites and the FILE | SAVE ALL does not work if you attempt to them in chunks.


Your thread ( viewtopic.php?f=1&t=3246&p=11439#p11439 ) was actually created after mine. But, it is neither a problem nor a competition of the faster poster.

I had skipped this part of the help file. But, as you say, it is a problem to open and save every page.
Still interesting to know about these features described in the help file here: Reusing code > code preprocessor.

Thx all.
BertrandH
 
Posts: 11
Joined: Sun Sep 07, 2008 8:36 pm

Re: Code snippets auto modification on several pages

Postby davenz » Mon Sep 08, 2008 11:08 am

Well, you can't do much better than this editor I think. I have used and/or trialled just about every editor made and available for download on the web looking for that perfect editor that has everything I want. The trouble is, that editor doesn't exist, but this one comes closest and is the one I use the most. It has features other editors don't have and also quirks that others don't have, but I like the ability to configure it how I like and to set the menus and colours to whatever I want. WeBuilder is probably way overpowered for the lame coding I do, but at the purchase price I may as well have the best tools even if the output isn't top notch!

Dave.
davenz
 

Re: Code snippets auto modification on several pages

Postby syrupcore » Mon Sep 08, 2008 9:58 pm

consider moving to PHP (or similar server side language) and using includes for repeated items like menus. You can do a find and replace now and replace all of your menus with the appropriate php include syntax. Then you can change whatever you like by updating that single file.

Actually, if you're looking at a 300 page website, I'd look into using a CMS of some sort. That way you can have you content and your presentation data totally separate.

Will
User avatar
syrupcore
Top Contributor
 
Posts: 917
Joined: Thu Jul 21, 2005 12:58 am
Location: Portland, Oregon, usa

Re: Code snippets auto modification on several pages

Postby BertrandH » Mon Sep 08, 2008 10:39 pm

I have just purchased a copy of RapidPHP 2008. :wink: :P

The PHP idea is nice but I want to avoid server side coding. I don't need dynamic coding at the moment (it will come later).
BertrandH
 
Posts: 11
Joined: Sun Sep 07, 2008 8:36 pm

Re: Code snippets auto modification on several pages

Postby syrupcore » Tue Sep 09, 2008 3:15 am

don't avoid it, embrace it. :) To do what you're trying to do is very very simple code. Not really "dynamic" nor cumbersome at all. I promise, it'll make your life easier.

Here's the article I read a few years ago that put me on the path. explains exactly what you're looking to do. http://www.mezzoblue.com/archives/2005/ ... ple_templ/
User avatar
syrupcore
Top Contributor
 
Posts: 917
Joined: Thu Jul 21, 2005 12:58 am
Location: Portland, Oregon, usa

Re: Code snippets auto modification on several pages

Postby BertrandH » Tue Sep 09, 2008 8:11 am

Thank you for the link. It is bookmarked now.

I have never done php, and want to learn it. That's why I am doing php pages now, but will come later.
BertrandH
 
Posts: 11
Joined: Sun Sep 07, 2008 8:36 pm

Re: Code snippets auto modification on several pages

Postby syrupcore » Tue Sep 09, 2008 9:17 am

I understand because I was really reluctant to deal with it for a long time myself. When dealing with a lot of pages, a tiny bit of PHP templating can save hairs. I need to keep all I have left so... That whole article is basically:

1. Dump all of your header html into a file called header.php
2. Delete all your header html from existing each page
3. Include a simple php include directive to header.php on each existing page in place of all that code.

You'd need to do some bulk file renaming and link href replacing (from .html to .php) but other than that, it's a really simple operation.

The whole middle section is just about how to pass info to header.php doc like your page title and page metadata. Basically just "text tokens", aka variables. I reckon it's worth the evening to investigate it. RapidPHP will make it easy and your hairline will thank you afterward. :)

Anyway, good luck and welcome to the forum.

Will
User avatar
syrupcore
Top Contributor
 
Posts: 917
Joined: Thu Jul 21, 2005 12:58 am
Location: Portland, Oregon, usa

Re: Code snippets auto modification on several pages

Postby BertrandH » Tue Sep 09, 2008 11:29 am

thx for the tips
BertrandH
 
Posts: 11
Joined: Sun Sep 07, 2008 8:36 pm

Re: Code snippets auto modification on several pages

Postby chrisjlocke » Thu Sep 11, 2008 9:38 am

I agree with Will that includes are so damn useful, and you don't need oodles of PHP code - just three lines (which can actually fit on one!!)
I'd also agree that a CMS is more of the way to go. If its a big site, a CMS prevents the need to update source files, save, upload via FTP etc. It also allows more than one person to easily amend pages in your site quickly and easily, again, without knowing much about FTP, HTML, etc.
Installing a CMS is easy nowadays with easy 'wizard' installers. You need to know a little bit about how your server is configured (what version of php, mySql, etc) but again, its worth it in the long run.

On my site, it takes just one change of a setting to transform the 'skin' so that it can look completely different, while retaining all the underlying data. More powerful than simply changing a CSS file! ;)
User avatar
chrisjlocke
Top Contributor
 
Posts: 995
Joined: Mon Aug 01, 2005 4:12 pm
Location: Essex, UK


Return to Web Developer Talk

Who is online

Users browsing this forum: Bing [Bot] and 10 guests