Get started with PHP

You must first create a project in Plasmic.

To view this quickstart with all the IDs and token placeholders replaced with real values, open your project in Plasmic Studio and press the “Code” button in the top toolbar.

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.

COMPONENTNAME refers to the name of the page or component that you want to render, such as Winter22LandingPage.

$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 (specifying the version numbers with the project names in the URL, i.e. /versioned/PROJECTID@VERSION/COMPONENT).

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 the API in the docs


Was this page helpful?

Have feedback on this page? Let us know on our forum.