Render modes
The PHP SDK has a single render input, RenderInput: the project and template slugs of a published template, plus the data array that fills its placeholders. Every render method takes it — $client->render->pdf(), $client->render->pdfStream(), $client->render->document() and the renderToFile() helper.
The render input
Section titled “The render input”use PoliPage\RenderInput;
$pdf = $client->render->pdf(new RenderInput( project: 'getting-started', template: 'welcome', data: ['name' => 'SDK Demo'],));There is no version to pick: the render uses the project’s copy published in the API key’s environment. A sandbox key renders what is published in sandbox, a live key what is published in live. To change what a key renders, publish the project to that key’s environment. No API key renders the draft.
RenderInput also takes the optional format, orientation, locale and metadata fields, plus the SDK-only idempotencyKey and timeout.
Trying a template
Section titled “Trying a template”The API renders only published templates. To try a template or a piece of HTML before you publish it, use the public playground at play.poli.page.
$client->documents->preview($id) stays: it returns the stored HTML of a document you already rendered.
Example
Section titled “Example”<?php
require __DIR__ . '/vendor/autoload.php';
use PoliPage\Orientation;use PoliPage\PageFormat;use PoliPage\PoliPage;use PoliPage\RenderInput;
$client = PoliPage::client($_ENV['POLI_PAGE_API_KEY']);
$pdf = $client->render->pdf(new RenderInput( project: 'billing', template: 'invoice', data: ['invoiceNumber' => 'INV-001', 'total' => 1280], format: PageFormat::A4, orientation: Orientation::Portrait, locale: 'en-US',));