# PHP variable in Schema data

**URL:** <https://forum.getkirby.com/t/php-variable-in-schema-data/23462>\
**Category:** Questions\
**Tags:** v3\
**Created:** [September 18, 2021, 10:17am UTC](https://forum.getkirby.com/t/php-variable-in-schema-data/23462 "2021-09-18T10:17:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fluxium](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@Fluxium](https://forum.getkirby.com/u/Fluxium)\
**Post date:** [September 18, 2021, 10:17am UTC](https://forum.getkirby.com/t/php-variable-in-schema-data/23462/1 "2021-09-18T10:17:05Z")

</div>

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

```auto
<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 🙂

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 18, 2021, 10:29am UTC](https://forum.getkirby.com/t/php-variable-in-schema-data/23462/2 "2021-09-18T10:29:03Z")

</div>

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

> [@Fluxium](#):
>
> ` "image": "<?= $page->image()->toFile->url() ?>",`

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:

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

```
