Categories > OpenTBS with DOCX >

Display block Conditionally

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Chris
Date: 2013-07-10
Time: 17:16

Display block Conditionally

I'm attempting to display an image in a docx, based on a condition in a block. I've tried every workaround I can think of, with no joy. This is the code I'm using, any suggestions?

[firstaidimg;block=begin;when [section.num]==’4’] MY IMAGE HERE [firstaidimg;block=end]

I'm creating 16 sections, the idea being that the image only shows in section 4. [section.num] is evaluating correctly, and I have tried the condition with both quotes around 4 and without - neither with any luck.

By this point, I presume I'm misunderstanding something. How would I make the above code give the correct result - and in addition, is there a way to target a particular image, without having to wrap it in a block?

Edit: The output I get from the above code looks like this:

[firstaidimg;block=begin;when 1==4] IMAGE HERE [firstaidimg;block=end]

Thanks in advance,
By: Sarah Kemp
Date: 2013-07-10
Time: 17:28

Re: Display block Conditionally

You need to make sure the image does exist in your template so TBS has a reference to manipulate - when the conditional is false you can just not display it using the same code you have now.

If you are using OpenTBS Beta 1.8.3 (it has been stable for me), you can put your TBS tags inside the Alt Text attribute of the image and use tagpos=inside to define the block.
By: Chris
Date: 2013-07-10
Time: 18:01

Re: Display block Conditionally

Sorry Sarah - I'm confused. The image is a physical image in my word doc, with the block tags wrapped around it. Is that correct?

I missed this from my previous post...my current output is:

[firstaidimg;block=begin;when 1==4] IMAGE HERE [firstaidimg;block=end]

(I have the same output where the var evaluates to
when 4==4
as well..)
By: Sarah Kemp
Date: 2013-07-10
Time: 18:23

Re: Display block Conditionally

Sorry, I may make this worse. All I ever do with pictures is change them, not delete them (except with blocks). I also way messed up the beta version I mentioned... the tagpos=inside is available since OpenTBS 1.8.0.

Yes, the image should be in the document as you describe, it wasn't clear whether you actually had an image in your template in your original post.

I think you may want to look at using parameter 'magnet' to delete the image from the pages you do not want it on, rather than using 'when' to display it. As I understand it, when is for uses that have some need of the value stored in the block or variable you are accessing (firstaidimage). mok:x (http://www.tinybutstrong.com/manual.php#html_field_prm_ope) may also be of interest to you, but I am no expert in these tags so unfortunately I probably can't help much more. If you are using Word 2010 for your template, you may want to experiment with a block definition of mc:AlternateContent or w:drawing.

I would try, in the Alt Text of your image, maybe something like:
[section.num;magnet=mc:AlternateContent;ope=mok:4;]
That's a wild guess on my part, but hopefully it gives you an idea of what I'm trying for. I think you can also use magnet with custom defined blocks like you are currently using, but I'm not sure of the syntax there.
By: Chris
Date: 2013-07-10
Time: 22:17

Re: Display block Conditionally

Great - thanks for the quick responses (on both posts!) I'll take another look in the next couple of days, and see what I can work out! :)

Cheers!
By: Chris
Date: 2013-07-12
Time: 11:24

Re: Display block Conditionally

For future searchers, putting the following code in the image alt text got the job done. Thanks Sarah!

[section.num;magnet=w:drawing;ope=mok:4;]
By: Sarah Kemp
Date: 2013-07-12
Time: 16:58

Re: Display block Conditionally

Thanks for posting back :)

One last note: If you are using 'preserve compatibility with past versions' when you save, make sure you try opening one of the files you produce in an older version. I'm not sure change the w:drawing will be enough if you have this option checked as the older versions do not use w:drawing. If you aren't using that option, no worries :)
By: Chris
Date: 2013-07-15
Time: 13:01

Re: Display block Conditionally

Thankfully not a concern for this system. I've got enough problems to worry about without having to think about backwards-compatibility haha!
Thanks!