Skip to content
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

Support for nested Object and scoping #149

Closed
wongjasont opened this issue Jul 27, 2015 · 11 comments
Closed

Support for nested Object and scoping #149

wongjasont opened this issue Jul 27, 2015 · 11 comments
Labels

Comments

@wongjasont
Copy link

Suppose I needed to create a word file to show this javascript object:

{
"title": "Something something dark side",
"sections": [
{
"title": "Yoda's inner dark side"
"chapters":[
{"title": "Something about darkness","description": "There's something about the darkness"},
{ "title": "So dark out there","description": "It is very dark outside, i swear" },
]
}
]
}

How do i set up a scope temporary variable, like:
{#sections as section}
{#section.chapters as chapter}
{/chapters}
{/sections}

and is there a way to integrate conditional formatting?

@edi9999
Copy link
Member

edi9999 commented Jul 27, 2015

You should probably use a custom parser

http://docxtemplater.readthedocs.org/en/latest/configuration.html#custom-parser.

@edi9999
Copy link
Member

edi9999 commented Jul 27, 2015

@wongjasont
Copy link
Author

Thanks! But i got that to work just by using the default parser, which is cool. But is there a way to add a newline character using a special character? I've tried using "/n" but it doesnt render.

@edi9999
Copy link
Member

edi9999 commented Jul 28, 2015

For adding new lines, see #144

@edi9999
Copy link
Member

edi9999 commented Jul 28, 2015

How did you got it to work ?

I believe everything is solved now so I'm closing this

@edi9999 edi9999 closed this as completed Jul 28, 2015
@wongjasont
Copy link
Author

I had to modify the object (scope/context) that i'm passing to setData, so that I won't need angular's functionality; so for "item.attributeX.attributeY" to work, i simply pushed attributeY to item, that way i won't need to use a scope variable item, so the template looks as simple as this:
{#items_1}
{item_1_attribute}
{#items_2}
{item_2_attribute}
{/items_2}
{/items_1}

from:
{#items_1 as item}
{item1.some_variable.item_1_attribute}
{#items_2}
{item2.some_variable.item_2_attribute}
{/items_2}
{/items_1}

It worked so I'm happy about it regardless. Thanks!

@jchabot86
Copy link

is this possible to do? i am referring to the initial request of this issue. i've noticed some instances where if an object within a nested loop has the same tag property as one in the parent loop, the scope refers up to the parent instead of the child. in this case the child would be "this"

@edi9999
Copy link
Member

edi9999 commented Feb 1, 2017

The rule is that docxtemplater takes the parent scope whenever the childscope returns null or undefined.

@jchabot86
Copy link

Is this something that can be avoided with nullGetter or a custom parser? I tried several things but no luck

@edi9999
Copy link
Member

edi9999 commented Feb 2, 2017

Can you explain in detail what your template is, data , and expected/actual output ?

@edi9999
Copy link
Member

edi9999 commented Feb 2, 2017

Yes, changing the custom parser could help, but without an idea of what your data looks like, it is quite difficult to give a better response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants