Jump to content
antknight

How to import HTML with images?

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By maba
      Hello,
      I need to import regularly - every 15 or 30 days - a big .xslx file into my PW installation.
      This file now has 14 columns, 5.000 rows and grows every month.
      I'll need to group, order and work with these data to:
      analyse User monthly costs analyse User costs per Asset ... User (real AD account) has to match with a PW user - I can't join to the domain - but as you can see I have some services users (start with sca_*) or no user at all. Those rows have to be assigned to a specific user, e.g. account100.
      And:
      I would like to be able to have a kind of diff function to compare User assets between this and last month (and so on) other request is to have a notification when something change for a User between actual and latest import First request: which is the best solution to store those data in your opinion? Page, Table, Repeater Matrix, ...?
      Those are very repetitive data and I think a page reference is better than to import all the data every time but I have to understand how to manage those "dynamic" groups of software (AccType Det), hardware (Asset), ... For example Price will be imported and not stored with the description because it could be change in the future and I'll not have any control on it.
      Thanks!
      User,OE,productNmr,AccType1,AccType Det,Count,Price (€),Sum,ASNA,CC,AccType Info,Asset,AccGroup,,,,,,,,,,,,,
    • By DooM
      Hey guys,
      I'm using Form builder module by Ryan and I'm trying to render HTML success message after form is sent using value from this field:

      but it renders exactly as it is written in the field, not as HTML. To render it I just use echo
      <?= $successMessage ?> What am I missing?
       
      Thanks for any help. 🧒
    • By dragan
      Is it by design that a site/ready.php is not included when creating a new site profile? Is it possible to include it with a hook? Or are there any security thoughts? (I don't want to redistribute it in public, it's just so I have my own boilerplate)
    • By Marcel
      Hey, 
      - we made a page as admins
      - as admins each  <img> tag is loaded and images are displayed
      - we tested the page as a pre-definded test user which is "guest" (Admin Theme: Reno)
      - as test user each <img> is missing and so no image is displayed
      I checked this in dev-mode on firefox and chrome. Does anyone have an idea or has had similar issues?
       
      Thank you in advance.
       
      Marcel
    • By karian
      I don't know why multiple instances (repeater_repeat_columns1, repeater_repeat_columns2, ...) of my repeater field are displayed inside Template field (see image).
      Is there a way to clean/reset it ?
       

×
×
  • Create New...