Get started with PHP

Get started with PHP

Render a page or component from Plasmic from PHP using the REST API. This returns plain HTML that you can render anywhere, optionally including Javascript-hydrated interactivity.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "");
// Provide the project ID and public API token.
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"x-plasmic-api-project-tokens: PROJECTID:APITOKEN"
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$result = json_decode($response);
echo $result->html;

The above use the /preview/ route, which fetches the latest revisions, whether or not they were published! Replace with /published/ to ensure you render only published changes, or /versioned/ to render specific versions.

If you want to publish only static content and don’t want to hydrate any Javascript (don’t need any interactivity), remove the query parameters hydrate and embedHydrate.

There’s much more to explore!

  • Perform server-side rendering.
  • Render different variants.
  • Override the content or props.
  • Add dynamic behavior.
Continue learning in the docs.