[英]PHP/OpenTBS/DocX nested arrays / subblock
Actually testing opentbs to generate a docx based on a template from my website. 实际测试opentbs以基于我网站上的模板生成docx。 I'm facing a problem integrating images.
我在集成图像时遇到问题。 I succeeded to add images inside a loop, but my problem is integrating those in a nested loop.
我成功在循环中添加了图像,但是我的问题是将它们集成到嵌套循环中。
I have an array of days Object and inside this an array of images path (with additional datas in each days) 我有一个天对象数组,并且在其中有一个图像路径数组(每天都有其他数据)
My data schema is like this: 我的数据架构是这样的:
// Initialisation du Parser
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
// Chargement du fichier Modèle
$TBS->LoadTemplate(realpath(dirname(__FILE__)).'/tbs/rendu-v2.docx', OPENTBS_ALREADY_UTF8);
$steps = array(
stdClass {
day: 'day 1',
name: 'My 1st step',
images: array(
'pathToMyFirstImage',
'pathToMySecondImage'
)
},
stdClass {
day: 'day 2 & 3',
name: 'My 2st step',
images: [
'pathToMyThirdImage',
'pathToMyFourthImage'
]
}
);
$TBS->MergeBlock( 'steps2', $steps);
$TBS->Show(OPENTBS_DOWNLOAD);
In my word Template: 用我的Word模板:
[steps2;block=begin]
JOUR [steps2.day;sub1=images] : [steps2.name]
[steps2.date]
[steps2.description]
[steps2_sub1; block=begin]
[X] (picture with [steps2_sub1.val;ope=changepic;tagpos=inside] as text sustitution)
[steps2_sub1; block=end]
[steps2; block=end]```
Actually, in the output file, my subblock is display as this and not interpreted. 实际上,在输出文件中,我的子块以此显示而不被解释。
I looked at this solution OpenTBS - How to use a double loop but end part is a little Strange and not working either with only [steps2_sub1;block=end]
. 我看过这个解决方案OpenTBS-如何使用双循环,但结尾部分
[steps2_sub1;block=end]
并且仅使用[steps2_sub1;block=end]
。
OpenTBS doc doesn't give full example of subblocks with block. OpenTBS文档未提供带有块的子块的完整示例。
Does anyone see what I misunderstand? 有人看到我误会了吗?
EDIT : My subblock doesn't work and is displayed as "code" and not interpreted. 编辑:我的子块不起作用,并且显示为“代码”且未解释。
Thanks, 谢谢,
Mathieu 马修
I can see 2 errors in your snippet. 我在您的代码段中看到2个错误。
1) TBS is case sensitive. 1)TBS区分大小写。
So the snippet: 因此,代码段:
[STEPS2.DAY;SUB1=IMAGES]
should be replaced with: 应替换为:
[steps2.day;sub1=images]
2) parameter 'sub1' is a block parameter, so it should be defined only in the field that has parameter 'block'. 2)参数“ sub1”是一个块参数,因此只能在具有参数“块”的字段中定义。 Otherwise it is ignored.
否则将被忽略。
So the snippet: 因此,代码段:
[steps2;block=begin]
[steps2.day;sub1=images]
should be replaced with: 应替换为:
[steps2;block=begin;sub1=images]
[steps2.day]
It appears that TBS is space sensitive : I had a space before semicolon of sub1 in my begin block (MS Word add it automaticaly in FR language). 看来TBS是对空间敏感的:我的begin块中sub1的分号前有一个空格(MS Word用FR语言自动添加)。
Working code is next : 接下来是工作代码:
[steps2;block=begin;sub1=images]
[STEPS2.DAY] : [STEPS2.NAME]
[steps2.date]
[steps2.description;strconv=no]
[X] <- Image with "[steps2_sub1.val;ope=changepic;tagpos=inside;block=tbs:p]" as Text Replacement
[steps2;block=end]
Thanks all 谢谢大家
By the way, how can I manage various way of displaying my pictures? 顺便说一句,如何管理显示图片的各种方式? I'll have 0 to 4 pictures to display like that :
我将显示0至4张图片,如下所示:
| My Page |
| |
| Case 1 image |
[ 100% Width ]
| |
| Case 2 images |
[ 50% ][ 50% ]
| |
| Case 3 images |
[ 50% ][ 50% ]
[ 100% ]
| |
| Case 4 images |
[ 50% ][ 50% ]
[ 50% ][ 50% ]
Is it possible to achieve something like this? 是否有可能实现这样的目标?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.