Yepp, got it right! So, based on Sarah's suggestions, I was able to fake linking rId's in the Word document's rels file and document.xml.
This is how I did:
In the word file, every link in the block points to a sample url
http://mypage.com
Doesn't matter which url you choose, and here's why: After the block is multiplied several times, all the links in these blocks will stay linked to the same<Realtionship>
tag in the rels file, and we are about to modify this connection, so no link will point to the originalmypage.com
<Relationship>
item.For this to happen, I inserted the following text after the actual text inside the link:
!-item.rId;att=w:hyperlink#r:id;-!
So my link now looks like :My website!-item.rId;att=w:hyperlink#r:id;-!
. What this tag does is that it changes the default r:id attribute of the link (which is the attribute Word links items by between thedocument.xml
and the rels file_rels/document.xml.rels
). The r:id will be changed to a custom id name, which you have to supply in the php array you merge by! Here's my php code for the rId's:$tmpl_items = array( array('title'=>'My title', 'url'=>'http://myurl.com/firstarticle','rId' => 'linkRid1'),
array('title'=>'My second title', 'url'=>'http://myurl.com/secondarticle','rId' => 'linkRid2'), array('title'=>'My third title', 'url'=>'http://myurl.com/thirdarticle','rId' => 'linkRid3') );notice, that rId is the value we will replace default r:ids with. Of course the openTBS tag gets removed from the link text.
- Hack the rels file.
!-item.block;block=begin;-! <Relationship Id="!-item.rId-!" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="!-item.url-!" TargetMode="External"/> !-item.block;block=end;-!
Run merge_block on the rels file too. This way,
<Relationship>
items will be generated by openTBS too. Also, this means, that by now, your Word file is corrupted, because you broke the valid XML syntax in the rels file, and cannot edit in in Word any more.$TBS->LoadTemplate('tbs/sampledoc_stackof2.docx'); $TBS->MergeBlock('item',$tmpl_items); $TBS->LoadTemplate('#word/_rels/document.xml.rels'); $TBS->MergeBlock('item',$tmpl_items);
After all this hassle, everything looks a-okay. I have these in the rels file:
<Relationship Id="linkRid1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://myurl.com/firstarticle" TargetMode="External"/>
<Relationship Id="linkRid2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://myurl.com/secondarticle" TargetMode="External"/>
<Relationship Id="linkRid3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://myurl.com/thirdarticle" TargetMode="External"/>
and I got the rId's in the document.xml too:
<w:p w:rsidRDefault="004842D8" w:rsidP="008A11F0">
<w:hyperlink r:id="linkRid1" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>
My website
</w:t>
</w:r>
</w:hyperlink>
</w:p>
Running openTBS now on the document will gerenate the docx file, with the merged links. The only downside is, that with the rels file hacked, I lost xml validity, and the chance to edit the document in Word later. Any suggestion, how to avoid that would be appriciated, although we'd need a solution where Word would keep the hacked parts of the rels file intact after saving the template doc.
Thanks Sarah for the great amount of help!
I'm opening a bottle of wine now.