Ah, I use child templates almost exclusivly. Is there a better way to achieve the description below? I wanted to make adding new sections contained and automated with using the right naming convention.
Currently what I'm doing is I create a base template file that loops through the sections. It then does the followng:
- Page break before every section so that sections don't overflow into another section.
- Set section header dynamically from section header value.
- Insert a child template based on the section name.
- If I pass the section with a name 'some-name', it will go and pull the same named child template 'some-name.html'.
- I also pass the section name / report type into the child template so that when I'm inside the template I can loop through the sections and access the correct section from the data I passed to the report.
The different reports I'm generating all follow the same pattern and layout so I don't need to create a bunch of chrome-pdf templates. The base-template is just there for rendering the child templates. Whenever people add new sections they only need to worry about adding one file.
File structure
root
research folder
section1-name (child-template)
section2-name (child-template)
section3-name (child-template)
base-report (chrome pdf template)
Data object
{
sections: [
name: 'some-name',
header: 'Some Name',
...,
subSections: [
{
name: 'some-name',
header: 'Some Name',
...
}
]
]
}
Base report chrome-pdf template
{{#each report.Sections}}
<div style='page-break-before: always;'></div>
{{#if Header}}
<div class="hide-data">{{{pdfCreatePagesGroup Header}}}</div>
{{/if}}
{{#if ../report.ReportType}}
{{{insertChildTemplate null Name 1}}}
{{else}}
{{{insertChildTemplate ../report.ResourceName Name 1}}}
{{/if}}
{{/if}}
{{/each}}
Child-template
{{#with (lookup report.Sections parentIndex)}}
...
{{/with}}