3

In my project I use TinyButStrong / OpenTBS to generate Word documents from templates. First I load a variable like myuser in the document.

[onload;tplvars;myuser=user]

The document is provided with the required variables, so I can add tags like this where the name is placed on the variable:

Hello [myuser.firstName]!

Also conditional values work fine:

[onshow;block=tbs:p;when [myuser.firstName]='John'] This is a paragraph just for John.

But when I have multiple paragraphs that I want to show/hide, it's not easy to select the correct paragraphs (or change the template and add a paragraph). Is it possible to create blocks that have a 'begin' and 'end' that are shown based on a value? Something like this (pseudocode):

Paragraph 1
[if [myuser.firstName] = 'John']
    (insert random number of paragraphs and maybe tables/other stuff here)
[end if]
Paragraph n

I could not find any of this in the TBS/OpenTBS docs. Does someone know a method to do this?

Thanks!

Niels

nielsr
  • 2,417
  • 2
  • 15
  • 16

1 Answers1

4

TBS has a block syntax [onshow;block=being]...[onshow;block=end] but it's a bad practice with OpenTBS because in fact in the inner XML those two tags are placed in a two separated <w:p> entities. So those entities will be split in two and it's a luck if they match with the newly merged contents.

One solution is to protect the begin/end tags with a paragraph entity.

[onshow;block=begin;enlarge=tbs:p;when ....] This paragraph will be deleted
Some text here.
Some text there.
[onshow;block=end;enlarge=tbs:p] This paragraph will be deleted

Another solution is to define a block on several paragraphs: This block is defined on 3 paragraphs:

[onshow;block=tbs:p+tbs:p+tbs:p;when ...] Paragraph 1 - inside the block
Paragraph 2 - inside  the block
Paragraph 3 - inside  the block
Paragraph 4 - outside the block

The other solution is

Benjamin Karlog
  • 330
  • 1
  • 6
  • 22
Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Thanks for your response, that helped a lot! For people that have the same question: the [onshow;block=begin ...] stuff should be in a separate paragraph since the entire paragraph is deleted. – nielsr Aug 29 '14 at 07:21
  • @nielsr how do you avoid that behavior? I have a text like: some text, "sometimes this text, " some other text Where I only sometimes want to show "sometimes this text," – Benjamin Karlog Mar 22 '18 at 16:58