Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Batch Create Multi HTML Pages

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #160304
    ChrisB
    Participant

    Hello 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,
    Chris

    #160316
    Paulie_D
    Member

    Look into using a CMS or PHP or AJAX.

    #160317
    chrisburton
    Participant

    What are you trying to build here?

    #160323
    ChrisB
    Participant

    Well 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.

    #160324
    Alen
    Participant

    You 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,
    -Alen

    #160405
    ChrisB
    Participant

    Hi 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,
    Chris

    #160406
    Alen
    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.

    #160408
    ChrisB
    Participant

    Thanks Alen, it is greatly appreciated. I am going to look into SQL as well.

    #160430
    Alen
    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();
        }
    }
    
    #160431
    Alen
    Participant

    Code above would create two files: one-title.html and two-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>
    
    #160470
    ChrisB
    Participant

    Alen,

    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,
    Chris

    #160548
    ChrisB
    Participant

    OK,

    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

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Other’ is closed to new topics and replies.