Comments (14)
If you want to test if the array is empty, you can use the inversed loop tags:
{#users}
User: {name}
{/users}
{^users}
No Users ...
{/users}
Will output "No Users ..." if the users array is empty
from docxtemplater.
Hey,
the way to do if else is to use table templating:
{#ifFormatting}
//table 1
{/ifFormatting}
{#elseFormatting}
// table 2
{/elseFormatting}
with the following data:
{
"ifFormatting":[], //This will not show what's inside ifFormatting
"elseFormatting":[{tableData:""}] //This will show what's inside elseFormatting once
}
from docxtemplater.
I will maybe add the possibility to use "ifFormating":true instead, without changing the working scope, so that would be the same as what Mustache does
from docxtemplater.
Actually I have added this functionality:
If the docx template is
{#ifFormatting}
{/ifFormatting}
and ifFormatting===true, then what is inside the scope will be shown and the scope won't be changed.
from docxtemplater.
how can i use array.length in if condition.
{#array.length}
{some_actions_with_array}
{/array.length}
seems to be not working
problem when i use {-w:p smth}{smth} when the array is empty
from docxtemplater.
got u, thanks)
from docxtemplater.
hi
can you also do something like this
{#myVar == 'value1'}
// pring if myVar is value1
{/}
Thanks
from docxtemplater.
Yes, search in the docs for angular parser
from docxtemplater.
i need if else condition like this
{#dogName} German {/} else not found
from docxtemplater.
Hello @adadi-arc ,
there are two possibilities :
- Use {#dogName} and then {^dogName}, like this :
{#dogName}German{/}{^dogName}not found{/}
or you can also use the angular expression parser and a ternary :
- {dogName ? " German " : "not found"}
This second solution needs the following code :
const expressionParser = require("docxtemplater/expressions.js");
const doc = new Docxtemplater(zip, {
paragraphLoop: true,
linebreaks: true,
parser: expressionParser,
});
doc.render({
first_name: "John",
last_name: "Doe",
phone: "0652455478",
description: "New Website",
});
from docxtemplater.
I have a question. Suppose there's a paragraph on a new page displayed depending on a condition. I want it to show the text when the condition is true; otherwise, it should generate a blank page. However, I don't want it to generate a blank page if the condition is false
from docxtemplater.
I think this could be solved by using the following trick :
https://docxtemplater.com/docs/faq/#adding-page-break-from-a-tag
from docxtemplater.
I'm encountering this error when using page break.
the tag \ pagebreak\ is not inside a paragraph, putting raw tags inside an inline loop is disallowed. ,
Can we connect on WhatsApp to discuss it?
from docxtemplater.
Please make sure first to upgrade to the latest docxtemplater version, 3.45.0
If you write your document like this :
{#cond}
{@pageBreak}
{text}
{/}
And use the following in your code :
const doc = new Docxtemplater(zip, {
paragraphLoop: true,
linebreaks: true,
});
doc.render({
cond: true,
pageBreak: '<w:p><w:r><w:br w:type="page"/></w:r></w:p>',
text: "Hello world",
});
(The paragraphLoop: true option is important, it will automatically remove empty paragraphs inside those types of loops).
It is not possible to add a {@Pagebreak} inside a given paragraph, for example :
Foo{@pageBreak}
is invalid, as well as :
{#cond}{@pageBreak}{/}
You have to write :
{#cond}
{@pageBreak}
{/}
If that still doesn't work and you have applied everything above, please send your template.
from docxtemplater.
Related Issues (20)
- ignore unopened tags error HOT 2
- Parser example to avoid using the parent scope if a value is null on the main scope : onlyDeepestScope bug HOT 11
- Make document readonly or password protected? HOT 4
- custom filters in segment not resolved with renderAsync HOT 1
- Open and edit a created document via webdav (Windows) creates additional rows in a table HOT 4
- The parser parses '()' incorrectly in case of using custom delimiters like this '$(', ')' HOT 6
- dropUnsupportedFileTypesModules called twice by constructor HOT 3
- Cannot resolve @Name placeholder HOT 2
- Chart Module: Unexpected Behavior with Null Value in Data HOT 3
- Differentiate between conditions and loops when getting tags HOT 1
- Conditional assignment doesn't work as expected HOT 1
- Page break propogates to all elements inside div HOT 5
- Numbering for conditional text HOT 3
- Question: Importing ExpressionParser in TypeScript. HOT 6
- When I write a tag in complex content, it doesn't work HOT 4
- HTMLModule Dependencies causing errors HOT 1
- paragraphLoop doesn't seem to work HOT 2
- ChartModule + ErrorLocationModule HOT 2
- Bun.sh HOT 1
- Trying to setup angular parser, but is failing with compilation error. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docxtemplater.