Forum


Replies: 11   Views: 5622
Problem with blocks
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by kdurolek  · 03-06-2014 - 13:47

I'm currently testing trial version by I'plan to buy corporate version of product (Maybe problem lies in a version I use). I have question about template blocks. Template example: $BLOCK_OVER18$Example text 1$BLOCK_OVER18$$BLOCK_LESS_THEN_18$ Example text 2$ BLOCK_LESS_THEN_18$ Problem 1) Code: $docx->deleteTemplateBlock('OVER18'); $docx->clearBlocks(); I expected to see text: "Example text 2" But I see blank line I can do this trick do achieve what I expected (not use clearBlocks). But it's not what I expect and what I found in docs. $docx->deleteTemplateBlock('OVER18'); $docx->cleanTemplateVariable('BLOCK_LESS_THEN_18','inline'); Problem 2) When my expression expands to multiple lines in Word (Like in my example 2 lines: some kind of conditional content) and I remove all block except f.e. one and I remove all block tags then I stay with 2 lines instead content from 1 block which fits to one line. Problem 3) When I remove block I stay with blank line. I found similar topic on forum but without answer. Please help me to achieve what I want.

Posted by jorge  · 03-06-2014 - 17:20

Hello, Did you downloaded the PRO trial 3.7 or the PRO trial 4.0? Regards.

Posted by kdurolek  · 04-06-2014 - 09:42

I was using v.3.7. Today I tried on v.4 and here are results: Problem 1) Still occurs. There is also a new problem. It doesn't look like cleanTemplateVariable is member of CreateDocxFromTemplate class. So my trick stopped working. Question how to use "cleanTemplateVariable'. Current API doc suggests it is member of CreateDocx class but tutorial and other methods suggests to use CreateDocxFromTemplate. If I will try to use old way with CreateDocx instance then we have a problem with not existing addTemplate method :). Problem 2) I cannot test because of existing bugs. Problem 3) Fixed. New problem. $docx = new CreateDocxFromTemplate($templatePath); $docx->clearBlocks(); $docx->createDocx('$filepath); removes all blocks with content from template. It should remove block tags and leave content.

Posted by jorge  · 04-06-2014 - 11:16

Hello, The new version uses a new class for the templates features that inheritance CreateDocx. So you need to instanciate the new class. Some methods have changed in the new version, for example cleanTemplateVarible is this method: http://www.phpdocx.com/api-documentation/templates/remove-template-variable Please refer to the included examples to get all needed info. Regards.

Posted by kdurolek  · 04-06-2014 - 12:25

Thank you for answer. removeTemplateVariable works and solves one small problem. I could test Problem 2 and it also resolves this issue. Can I ask for help with remaining problems? Regards

Posted by jorge  · 04-06-2014 - 13:09

Hello, As you're using the trial version I recommend you to check the included examples and the documentation. We can help with minor issues or bugs but not custom scripts unless you get a subscription or support tickets. Regards.

Posted by kdurolek  · 05-06-2014 - 09:35

I perfectly understand that for more complex help we should pay. But issues that I found looks like bugs. My scripts have 3/4 lines and template used for tests has max 3 lines. So in my opinion I'm not doing anything unusual. I just try to use basic functions of library. I'm responsible for recommendation of the best library to my company that's why I have to know if it can handle our requirements. I will try to be brief. PROBLEM 1 Template: Say $BLOCK_A$Aaa$BLOCK_A$ $BLOCK_B$Bee$BLOCK_B$ Code: $docx = new \Phpdocx_Phpdocx($templatePath); $docx->clearBlocks(); $docx->createDocx($docPath)); Expected: Say Aaa Bee Result Just "Say". It removed block tags with content instead of just block tags. PROBLEM 2 Template: Say $BLOCK_A$Aaa$BLOCK_A$$BLOCK_B$Bee$BLOCK_B$ Code: $docx = new \Phpdocx_Phpdocx($templatePath); $docx->deleteTemplateBlock('A'); $docx->createDocx($docPath); Expected: Say Bee Result Blank document. Whole content was removed. SUMMARY As you see it's hard to call my code and template complex. But results that I got are more then surprising. I tried to look for some information in documentation but there is no information about detail behavior of this functions. Regards

Posted by jorge  · 05-06-2014 - 10:55

Hello, We'll check it, if we find any bug it'll be solved. Regards.

Posted by kdurolek  · 10-06-2014 - 09:40

Hello, I jest wanted to ask if you already have solution to described problems? Regads Krzysztof

Posted by admin  · 10-06-2014 - 10:58

Hello, The method clearBlocks remove the whole content inside the block variable, not only the placeholders. And the method deleteTemplateBlock remove the paragraph where the BLOCK is added. So each BLOCK must have it own paragraph. Regards.

Posted by legalvision  · 16-10-2014 - 04:09

We are evaluating phpdocx and have come across the same issue as kdurolek outlined in "Problem 1". Here is an example line of text in our template: Signed, sealed and delivered by XYZ $BLOCK_1A$ (ABN $1B$) $BLOCK_1A$ If the 1B variable is empty, we need to remove the "(ABN $1B$)" text from this line, so it reads: Signed, sealed and delivered by XYZ If we do a simple test by using this code: $docx->deleteTemplateBlock('1A'); The entire line of text is remove (not just the ABN... part). Is there a way around this, or a different function/method we should be using?

Posted by admin  · 16-10-2014 - 06:22

Hello, Both methods, clearBlocks and deleteTemplateBlock, removes the whole paragraph, and there's no option to remove a stub of the string. Regards.