title: Set dynamic header and footer data on PDF generation from rails (Grover gem)
body: <p>Using this gem so I can run NodeJS Puppeteer from Rails:</p>
  
  <p><a href="https://github.com/Studiosity/grover" rel="nofollow noreferrer">https://github.com/Studiosity/grover</a></p>
  
  <p>I'm trying to render different reports in HTML to a PDF file so the users can download them.</p>
  
  <p>When doing this through a middleware, I have the <code>config/initializers/grover.rb</code>:</p>
  
  <pre><code>Grover.configure do |config|
    view = ActionView::Base.new(ActionController::Base.view_paths, {})
  
    header_template = view.render(:template =&gt; "pdf/_header", :layout =&gt; false, :spa =&gt; spa, :codigo =&gt; codigo)
    footer_template = view.render(:template =&gt; "pdf/_footer", :layout =&gt; false, :doctitle =&gt; @doctitle, :spa =&gt; spa, :codigo =&gt; codigo, :page =&gt; page, :topage =&gt; topage)
  
    config.options = {
      display_url: Settings.corporativo,
      format: 'A4',
      margin: {
        top: '0.8in',
        bottom: '0.65in',
        right: '0.45in',
        left: '0.5in'
      },
      prefer_css_page_size: true, #Doesn't seem to work. Still the margins set here are the ones that rule.
      display_header_footer: true,
      header_template: header_template,
      footer_template: footer_template,
      print_background: true,
      emulate_media: 'print',
      cache: false,
      timeout: 0
    }
  end
  </code></pre>
  
  <p>Do you have an idea of how I could pass dynamic parameters to these templates? Because, setting this templates in initializing time makes them static as far as I can tell...</p>
  
  <p>Here, one of my templates <code>_footer.html.haml</code>:</p>
  
  <pre><code>%footer{:style =&gt; "display:flex; justify-content: space-between; font-size:6px !important; width: calc(100% - 0.75in); margin: 0 auto;"}
    %span.title
    #description{:style =&gt; "text-align:center;font-size: 6px;"}
      - if !@codigo.nil?
        = raw t('pdfkit.footer_E')
      - else
        = raw t('pdfkit.footer')
    .pageContainer
      %span.pageNumber
      = "/"
      %span.totalPages
  </code></pre>