Skip to content

Commit 9a5c76a

Browse files
authored
Fix header and Footer configuration (#124)
1 parent 70a9e28 commit 9a5c76a

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

docs/configuration.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,30 @@ sensiolabs_gotenberg:
12411241
> For more information about the [PDF properties](https://gotenberg.dev/docs/routes#page-properties-chromium)
12421242
> or [screenshot properties](https://gotenberg.dev/docs/routes#screenshots-route).
12431243
1244+
## Header and footer defaults templates
1245+
1246+
You have the option to add a default header and/or footer template to your PDF.
1247+
If your template contains variables, simply enter its name and value under `context`
1248+
as shown below.
1249+
1250+
```yaml
1251+
sensiolabs_gotenberg:
1252+
http_client: 'gotenberg.client'
1253+
assets_directory: 'assets'
1254+
default_options:
1255+
pdf:
1256+
html:
1257+
header:
1258+
template: 'header.html.twig'
1259+
context:
1260+
title: 'Hello'
1261+
first_name: 'Jean Michel'
1262+
footer:
1263+
template: 'footer.html.twig'
1264+
context:
1265+
foo: 'bar'
1266+
```
1267+
12441268
## Extra HTTP headers
12451269
12461270
HTTP headers to send by Chromium while loading the HTML document.

src/DependencyInjection/Configuration.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,15 @@ private function addChromiumPdfOptionsNode(ArrayNodeDefinition $parent): void
173173
->children()
174174
->scalarNode('template')
175175
->info('Default header twig template to apply.')
176-
->defaultNull()
176+
->isRequired()
177+
->cannotBeEmpty()
177178
->end()
178-
->scalarNode('context')
179+
->arrayNode('context')
179180
->info('Default context for header twig template.')
180181
->defaultValue([])
182+
->normalizeKeys(false)
183+
->variablePrototype()
184+
->end()
181185
->end()
182186
->end()
183187
->end()
@@ -186,11 +190,15 @@ private function addChromiumPdfOptionsNode(ArrayNodeDefinition $parent): void
186190
->children()
187191
->scalarNode('template')
188192
->info('Default footer twig template to apply.')
189-
->defaultNull()
193+
->isRequired()
194+
->cannotBeEmpty()
190195
->end()
191-
->scalarNode('context')
196+
->arrayNode('context')
192197
->info('Default context for footer twig template.')
193198
->defaultValue([])
199+
->normalizeKeys(false)
200+
->variablePrototype()
201+
->end()
194202
->end()
195203
->end()
196204
->end()

0 commit comments

Comments
 (0)