-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditions in Templates #1394
Comments
Why do you want to put this in the template file? I think this kind of logic is fairly "edge-case" and to implement this level of conditional logic into the library is a bit hectic and will add to maintenance complexity. Doing this yourself in the current code is quite easy:
PHP
Not sure how many cases you have where you'd need this kind of conditional logic, but I'm pretty sure it will be easier to manage the code in your controller than trying to implement it into the library and your templates. |
I support this request. |
I agree with @rkorebrits ,and @gruessung can fit your requirement with this way: |
@icy2003 @rkorebrits Ofc I am fully aware how this can be done in the code rather than in the template (as mentioned in my original PR "...rather than in the code."). The reason why this makes sense is the same reason templating languages exist at all: separation of concerns. |
Better
or
To avoid mixing variables and functions. |
is this the next version function? |
I don't see the difference in the first one? Did you mean the first "or" the second one or the second one instead of the first one. Any other issues someone sees with this feature? |
This doesn't seem to work within a numbered list. |
Any news on this? Would really solve a lot of hassle in multiple implementations. Python's docx templating lib supports Jinja2 - which also provides in-template-logic handling, so would be good to see it here in PhpWord |
Is any update on this issue? |
Any update? 😀 Maybe I should just start implementing myself I guess... |
Hello Community, @vpiskunov Thanks for your suggestion of using python-docx-template. It sure looks promising for handling the in-template logic. I was wondering if we have any update on this request though? I believe the following reasons are worth considering for developing this feature.
|
I moved over to OpenTBS around the time I first noticed this issue. Works like a charm for my needs. |
My template has boolean variables, this variables can be "Yes" or "No" for using in template. I solve this problem with small function:
in template I have row "IF(VARIABLE;True text;else text)" Example of use:
And example for cloned blocks:
|
I also require this functionality. Using the setValue method to assign an empty value doesn't eliminate the element; rather, it merely empties the text, leaving a line in the document, which is less than ideal. Create a new class that extends TemplateProcessor and incorporated a new method called removeValue.
hope it helps! |
This is:
Expected Behavior
Being able to put conditions in a template block rather than in the code.
Current macros only support replacement and repeats (clone, replace, set).
I want to start a discussion about this before I might implement it and send a PR.
I guess it would look something like that:
In the docx "template":
In the code:
This could be extended by several operands (<, >, <=, >=, !=, ==) or even nested logical expressions.
Pro:
More transparent templates (view logic where it belongs)
Con:
More complexity in template processor
The text was updated successfully, but these errors were encountered: