I have a list of images filled with url, or empty in some case. I just want to display the images when the url exists, and not display the image when the url is not specified. There is a very similar post here, but not fully answered, so I am posting this again.
Here is my php array:
$myBlock = array(
'description' => ...,
'name' => ...,
'photos' =>
array (
0 => string 'C:\path_to\pic_5491y.png'
1 => string 'C:\path_to\pic_5491y.png'
2 => string 'C:\path_to\pic_5491y.png'
3 => int 0
...
9 => int 0
10 => int 0
)
);
I then try to display the image inside a block (at the moment, I only try with the first photo)
[myBlock; block=begin]
(the image I am trying to replace, or hide)
[CODE]
[myBlock; block=end]
And here are what I have tried to put in the [CODE]
, with what happens:
[myBlock.photos.0;ope=addpic;att=draw:image#xlink:href;when [myBlock.photos.0]!=0]
==>> Undefined property: clsTbsLocator::$PrevPosBeg
[myBlock.photos.0;ope=changepic;from=[val];tagpos=inside;adjust;unique;]
[myBlock.photos.0;ope=changepic;from=[val];tagpos=inside;adjust;unique; onshow; when[myBlock.photos.0] != 0]
(same as before but with the when
, which in the end does not change anything)
==>> The picture "0" that is supposed to be added because of parameter "ope=changepic" of the field [myBlock.photos.0] is not found.
(that is caused when the image has 0 as its url)
[onShow; if[myBlock.photos.0] != 0; then[myBlock.photos.0] :drawing; else ‘1’]
==>> [onShow; if0 != 0; then0 :drawing; else '1']
(just display that on the document)
[onshow; if[myBlock.photos.0] = 0 ; then ‘’ ; else from=[ myBlock.photos.0]; ope=changepic; tagpos=inside;adjust;unique]
==>> no errors, but don't replace any images, even when set
Thanks a lot in advance, and let me know if you need more details !
EDIT
Skrol's suggestions works perpectly when I use
$TBS->MergeBlock('myBlock', $myBlock['photos']);
But I am actually trying to merge directly $myBlock
, and therefore in my word document, trying to do a "double foreach"
I am failing creating a double block in my template (the reason is that I am trying to display some info before the photos.)
I am trying to do :
[myBlock; block=begin]
[myBlock.description] // => Display description before displaying the photos
[myBlock.photos; block=begin]
[myBlock.photos; block=end]
[myBlock; block=end]
But as soon as I add the second myBlock.photos
so I could loop through them, I have this error: in block's definition [myBlock...]: a least one tag with parameter 'block=end' is missing.
EDIT BIS
After trying several things, with same code, I managed to get rid of the error, probably because of a bad hidden caracter somewhere. But it is now trying to display the second block, instead of creating a new foreach
:
This is description 1
array
array
This is description 2
array
array
....
If that helps getting a better picture of what I am trying to achieve, here the equivalent I would use in PHP
:
foreach( $myBlock as $myBlockKey => $myBlockData)
{
echo $myBlockData['description'];
echo $myBlockData['name'];
...
foreach( $myBlockData['photos'] as $photoKey => $photoData)
{
echo $photoData['url'];
}
}
Any idea about how to get this double block defined ??? I could not find any exemple in the doc, or anywhere else :(
In order to merge the images stored in $myBlock['photos']
, your code should be like this :
PHP :
$TBS->MergeBlock('myBlock', $myBlock['photos']);
DOCX :
[myBlock; block=begin; when 0!=[myBlock.val]]
(the image I am trying to replace, or hide)
[myBlock.val;ope=changepic;tagpos=after;adjust;unique;]
[myBlock; block=end]
Explanations :
MergeBlock()
does merge data structured as a record-set. That is a set of records having the same structure. In your snipped, only $myBlock['photos']
is a record-set. Since each record is directly a value, you can use the virtual columns val
and key
to reach the data.when 0!=[myBlock.val]
makes the block section to be conditional. So only records with a value different from 0 will be displayed.tagpos=after
should be used because the TBS tag is placed after the image.