1

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 :(

Community
  • 1
  • 1
mokk
  • 916
  • 17
  • 35
  • What are you merging the block with ? I.e. what is your `MergeBlock()` command ? – Skrol29 Jan 28 '16 at 18:09
  • 1
    Yes you are right, I am doing `$TBS->MergeBlock('myBlock', $myBlock);` – mokk Jan 28 '16 at 18:28
  • 1
    What does contain the item `$myBlock['extra_data'] ?` When you talk about URL do you mean the path of the image such as `'C:\path_to\pic_5491y.png'` ? You want several images merged at the end or just only one ? – Skrol29 Jan 28 '16 at 22:04
  • Thanks for coming back to me Skrol !! The `extra_data` contains information that I display before the photos like `title`, `decription`, ... Then, if `$myBlock['photos']` has 3 elements, I want TBS to automatically displays the 3 photos. If it has 5 elements, to display these 5 photos, as the number of photos attached varies. And yes, by `URL` I meant the path, sorry for the confusion! – mokk Jan 30 '16 at 15:03

1 Answers1

2

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 :

  • Command 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.
  • Parameter when 0!=[myBlock.val] makes the block section to be conditional. So only records with a value different from 0 will be displayed.
  • Parameter tagpos=after should be used because the TBS tag is placed after the image.
Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Thank you for that Skrol, works really well if I merge `$myBlock['photos']`. I am now trying to assign `$myBlock` as specified in my EDIT, so basically trying in word to loop through `myBlock`, display few information, and the inside this loop, loop again through the `photos` and then show them. It is failing so far, I have few things I want to try tonight to fix it, I will let you know how it goes ! – mokk Feb 02 '16 at 10:16
  • 1
    So as mentionned, I tried few more things, but with no success. Your exemple works really well, but only If I am trying to display an array of a depth of 1. As soon as I try to manipulate my original `$myBlock` which have general information on the 1st level, and some photos saved as a 2nd level array, I can't get anywhere with definiing a second block inside the first one (hope I make sense, and my edits help!) Do you have any ideas on how to declare and manipulate a block inside another block ?? – mokk Feb 02 '16 at 21:04
  • My post is becoming super messy, I will tidy it up to have a simple question with your answer, and create another post for this double loop issue. Thanks again ! – mokk Feb 02 '16 at 21:19