问题
I am trying to create a block
inside a sub block
in a .docx
using openTBS
, with no success so far.
Here is my PHP
array
:
$myBlock = array(
0 => array(
'description' => 'description1',
'name' => 'name1',
'photos' => array (
0 => array(
'path' => 'C:\path_to\pic_0000y.png',
'name' => 'photo0000'),
1 => array(
'path' => 'C:\path_to\pic_1111y.png',
'name' => 'photo111'),
), // end of photo array
), // end of first element
1 => array(
'description' => 'description2',
'name' => 'name2',
'photos' => array (
0 => array(
'path' => 'C:\path_to\pic_3333y.png',
'name' => 'photo3333'),
1 => array(
'path' => 'C:\path_to\pic_00000.png',
'name' => 'photo00000'),
), // end of photo array
), // end of second element
);
Which I am merging into TBS
like this:
$this->TBS->MergeBlock( 'myBlock', $myBlock);
An equivalent in php
of what I am trying to achieve:
foreach( $myBlock as $myBlockKey => $myBlockData)
{
echo $myBlockData['description'];
echo $myBlockData['name'];
foreach( $myBlockData['photos'] as $photoKey => $photoData)
{
echo $photoData['name'];
echo $photoData['path'];
}
}
Which would display:
description1
name1
photo0000
C:\path_to\pic_0000y.png
photo111
C:\path_to\pic_1111y.png
description2
name2
photo3333
C:\path_to\pic_3333y.png
photo0000
C:\path_to\pic_0000y.png
I guess there is not much point of posting wrong things that I have tried, but that is pretty much what I tried to do:
[myBlock; block=begin;]
[myBlock.description]
[myBlock.name]
[myBlock.photos; block = begin;] // where it fails
[myBlock.photos.path] // where it fails
[myBlock.photos.name] // where it fails
[myBlock.photos; block=end;] // where it fails
[myBlock; block=end;]
回答1:
You have to use the TBS automatic sub-block feature.
[myBlock; block=begin;sub1=photos]
[myBlock.description]
[myBlock.name]
[myBlock_sub1; block = begin;]
[myBlock_sub1.path]
[myBlock_sub1.name]
[myBlock_sub1.photos; block=end;]
[myBlock; block=end;]
Your syntax with [myBlock.photos;block = begin] cannot work because (1) the block bounds for [myBlock] has already been defined, so parameter "block" in this tag is ignored. And (2) [myBlock.photos] is an item which is an array so it cannot be displayed.
来源:https://stackoverflow.com/questions/35164365/opentbs-how-to-use-a-double-loop