Search code examples
phpopentbs

OpenTBS / PHP / PowerPoint Template - How do I merge text across multiple slides?


I am trying to merge a text to multiple slides using OpenTBS but can not get the [a.ProjectName] to be replaced in the title of multiple slides.

I followed the demo in OpenTBS but when I use the code below to retrieve the Project Name I can not get the block substitution to succeed.

This is the code I have used:

  $data = array ('ProjectName' => $manageProjectName->getProjectName());

  $TBS->MergeBlock('a', $data);

  $TBS->Plugin(OPENTBS_SELECT_SLIDE, 1, true);  //true means use slide master but it is not having any effect     

How can I get the [a.ProjectName] to be replaced with the contents of the ProjectName across multiple slides and merge contents of ProjectName to multiple slides using OpenTBS?


Solution

  • Here are the points to take in account in your case :

    • You have to select a slide before to merge something on it (MergeBlock(), MergeField(), and automatic fields [onload], [onshow]).
    • But OpenTBS automatically select the normal slide #1 when you call LoadTemplate().
    • Master slides are specific slides that you have to select explicitly with command OPENTBS_SELECT_SLIDE.

    Another problem in your snippet is that you seem to confuse MergeBlock() and MergeField(). MergeBlock() is for merging data that are recordsets (several records, having several fields) ; thus the block is repeated as many times as they are records. MergeField() is for merging items, just like in your snippet.

    So your code should be:

    $data = array ('ProjectName' => $manageProjectName->getProjectName());
    
    // Merging [a.ProjectName] in the master slide #1
    $TBS->Plugin(OPENTBS_SELECT_SLIDE, 1, true); 
    $TBS->MergeField('a', $data);
    
    // Merging [a.ProjectName] in the normal slide #1
    $TBS->Plugin(OPENTBS_SELECT_SLIDE, 1); 
    $TBS->MergeField('a', $data);