PHP variable in Schema data

Hello people!
I was wondering if there’s some way to use variables in JSON Schema data.
Tried this, which doesn’t work:

<script type="application/ld+json">
{
  "@context": "https://schema.org/", 
  "@type": "Product", 
  "name": "<?= $page->name() ?>",
  "image": "<?= $page->image()->toFile->url() ?>",
  "description": "<?= $page->desc() ?>",
  // more...
  }
}
</script>

I have some product review pages where I want to insert this into the template.
Thanks in advance :slight_smile:

In general, you code should work. What is the error you get? Or the result?

This doesn’t make sense, because you are trying to turn an image object to file. Use toFile() if you want to convert a field value. Additionally, you should test for an image object before you call the url() method:

<?= ($image = $page->image()) ? $image->url() : '' ?>