Jump to content

How to import HTML with images?


antknight
 Share

Recommended Posts

I am after a bit of guidance on importing content to ProcessWire. I am using a program called Clarify to generate work instructions. I would like to use ProcessWire to put together a knowledgebase of work instructions.

I have Clarify outputting an HTML file and a folder of images for each work instruction which I would like to become a page in PW.

An example of the HTML output is attached.

How can I import these pages and the folder of images and keep the image links intact?

Many Thanks

Anthony

clarify-example.zip

Link to comment
Share on other sites

For the topic how to import / batchimport content into PW you will find many posts with examples in the forums, - so I will focus on your special issue with your images that are linked to "./images/...." in your htmlContent.

Assumed, you use an importer script, that reads the following from a source:

  • title / name of an entry
  • html content
  • images basenames

Assumed, that the importer script can access the imagefiles / knows where they are kept for the import.
And assumed that you have created a template with fields for those pages you want to create during the import.
Then you will come to a point, where you programatically create a new page:

$p = new Page($myTemplateObject);
$p->of(false);
$p->title = $theEntryTitle;
$p->parent = $theParentContainerPage;
$p->save();

Now you can add / import your images to an imagefield:

foreach($imagebasenameArray as $basename) {
    $p->imagefield->add($directorypathToImages . $basename);
}

Now all images of that entry resides in /site/assets/files/{PAGE_ID}/. And you have to modify your html-content to match this:

$p->body = str_replace("./images/", $config->urls->files . $p->id . "/", $htmlContent);
$p->save();

This way you will have the most possible flexibility with your pages, I think.

 

Please note: written in the browser, - may have bugs, - is meant as pseudo code. :)

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...