Skip to content

client.render.preview

client.render.preview(template:, data:, project: nil, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil)

POST /v1/render/preview — render and return the HTML, total page count, and the environment (“sandbox” / “live”) inferred from the API key. Accepts both project mode and inline mode (the only render-* method that does).

Name Type Required Description
template String required template slug (project mode) OR raw HTML (inline mode)
data Hash required template data
project String, nil project slug; required for project mode
version String, nil exact semver (e.g. "1.0.0") or "draft"
format String, nil one of `PoliPage::PageFormat::FORMATS`; default A4
orientation String, nil "portrait" or "landscape"; default portrait
locale String, nil BCP 47 (e.g. "en-US")
metadata Hash, nil primitive-valued metadata echoed on render.document responses
idempotency_key String, nil caller-supplied UUID; auto-generated if nil

PoliPage::PreviewResult

Code When
PoliPage::ValidationError See [errors](../../../production/errors/) for the full description.
PoliPage::NotFoundError See [errors](../../../production/errors/) for the full description.
PoliPage::AuthenticationError See [errors](../../../production/errors/) for the full description.
PoliPage::RateLimitError See [errors](../../../production/errors/) for the full description.
PoliPage::InternalError See [errors](../../../production/errors/) for the full description.
PoliPage::APIError See [errors](../../../production/errors/) for the full description.
# frozen_string_literal: true
# Demonstrates: client.render.preview — render and return HTML + page count.
# The only render-* method that accepts both project mode and inline mode.
require "poli_page"
client = PoliPage::Client.new(api_key: ENV.fetch("POLI_PAGE_API_KEY"))
# Project mode — render a stored template to HTML.
result = client.render.preview(
project: "billing",
template: "invoice",
data: { invoice_number: "INV-001", total: 1280 }
)
puts "#{result.total_pages} page(s) in #{result.environment} mode"
puts "HTML length: #{result.html.length} chars"
# Inline mode — pass raw HTML directly. Useful for debugging template data
# without engaging the PDF pipeline.
greeting = client.render.preview(
template: "<h1>Hello {{ name }}</h1>",
data: { name: "World" }
)
puts greeting.html