- This topic is empty.
-
AuthorPosts
-
January 13, 2014 at 1:49 pm #160304
ChrisB
ParticipantHello All,
I have a static HTML page and I need to make copies of that page but with a few changes in the content’s text. Is there a program that can automatically do this in some kind of batch process. I would need it to be much like how mail merge works in MS Word, where it pulls variables from an external file, replaces one line, and then saves that file as a new HTML doc. Anything close to this would be a huge help.
Thanks,
ChrisJanuary 13, 2014 at 3:27 pm #160316Paulie_D
MemberLook into using a CMS or PHP or AJAX.
January 13, 2014 at 3:36 pm #160317chrisburton
ParticipantWhat are you trying to build here?
January 13, 2014 at 4:44 pm #160323ChrisB
ParticipantWell I have a static website and I would like to have copies of some of the pages, but with slightly different title, description, and H1 tags. Everything else on that page would be the same. This would be repeated a couple hundred times so I was hoping there was an easy way.
I have found a program call HTML enforcer but that will change multiple pages to the same title tag but thats not what I need.
Thanks for the quick response.
January 13, 2014 at 5:18 pm #160324Alen
ParticipantYou mention mail merge Word uses. Data usually comes from some sort of comma separated list or excel sheet…. where is the data coming from that you want to create these pages form?
I would imagine small PHP program can be made to pull info from JSON, XML, Database or whatever and create these files for you. But that still begs the question in what format is the source?
However, I would strongly suggest you make a move to switch to some kind of content management system that employs templating especially if you plan on continuing working with the system. It will make your life easier.
Hope that helps,
-AlenJanuary 14, 2014 at 11:38 am #160405ChrisB
ParticipantHi Alen,
Thanks for the input. I have the source in an excel file so I was hoping I could just point it to that file. I don’t have too much experience with CMSs, I have only worked with wordpress. I tried to teach myself joomla and failed.
With wordpress I can change the header file but that would make all the meta tags the same through out the website which is not what I need.
I bet there is some kind of php that will do it but I have no clue on how to use it. Can you recommend a website or book that might help me reach my goal?
Thanks again,
ChrisJanuary 14, 2014 at 11:51 am #160406Alen
Participant@ChrisB, Excel can export SQL, so I would write some logic to pull this from database… but since you’re not familiar with that… I’m not sure what to suggest. Let me do some research later on when I have time and I’ll see if I can be of any help.
January 14, 2014 at 12:23 pm #160408ChrisB
ParticipantThanks Alen, it is greatly appreciated. I am going to look into SQL as well.
January 14, 2014 at 8:01 pm #160430Alen
Participant@ChrisB can you show us the html code (sample page, and what needs to change) and how the source data is structured? I’ve been researching and just can’t find anything (maybe am just Googling the wrong thing…) anyways.. with PHP you could do something like this:
// Our Data $data = array( array( 'title' => 'One Title', 'content' => 'One Content' ), array( 'title' => 'Two Title', 'content' => 'Two Content' ) ); // Iterate over data and format our output foreach ($data as $value) { $output = <<<HTML <html> <head> <title>{$value["title"]}</title> </head> <body> <h1>{$value["title"]}</h1> <p>{$value["content"]}</p> </body> </html> HTML; try { // (3(2(1))) // (1) Replace " " with "-" // (2) Convert to lowercase // (3) Write each file to disk // Takes 'title' => 'One Title' and converts it into one-title // Add .html extension file_put_contents(strtolower(preg_replace('/[\s-]+/', '-', $value["title"])) . ".html", $output); // This will create 2 files based on data provided } catch(Exception $e) { echo $e->getMessage(); } }
January 14, 2014 at 8:04 pm #160431Alen
ParticipantCode above would create two files:
one-title.html
andtwo-title.html
depending on how your input data is structured maybe you could expand on the script and modify it to fit your needs. Let me know if you need any help.Sample HTML code output:
<html> <head> <title>One Title</title> </head> <body> <h1>One Title</h1> <p>One Content</p> </body> </html>
January 15, 2014 at 11:48 am #160470ChrisB
ParticipantAlen,
Thanks for all your help. I have been doing some reach into this and came up with somewhat of a “cheating” way to achieve my goal. I think I am going to use MS word and mail merge plus a plug-in that will save as individual HTML file instead of printing. I still have to test my theory but I think it will work.
I don’t want to waste anymore of your time but I do appreciate all of your advice. I am plan to learn some php in case I have to do something like this again in the future. I will keep you updated on my progress.
Thanks again,
ChrisJanuary 16, 2014 at 12:33 pm #160548ChrisB
ParticipantOK,
So I have reached my goal, some what sloppily. I copied the html code into a word doc, then used mail merge with an add-on created by Graham Mayor (http://www.gmayor.com/individual_merge_letters.htm) which will save individual mail merge doc instead of one large file.
I saved them as a txt files and then used ReNamer (http://download.cnet.com/ReNamer/3000-2248_4-10590705.html) to fixed the file names and changed the extensions to .html. It is not the best way but its all I could do in the short time frame I have to finish this project. I still have to adjust the original code to use absolute links but the proof of concept work during testing.
I want to thank everyone for they’re help.
-Chris
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.