# Undefined variable in snippet

**URL:** <https://forum.getkirby.com/t/undefined-variable-in-snippet/321>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 6, 2015, 1:31pm UTC](https://forum.getkirby.com/t/undefined-variable-in-snippet/321 "2015-03-06T13:31:57Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![daizumi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/daizumi/32/11799_2.png) [@daizumi](https://forum.getkirby.com/u/daizumi)\
**Post date:** [March 23, 2015, 8:02pm UTC](https://forum.getkirby.com/t/undefined-variable-in-snippet/321/5 "2015-03-23T20:02:40Z")

</div>

So, what happens if I want to call this variable in the template after modifying it in the snippet. Let’s say I want to do something like this:

```
<?php $color = "used to be black"; ?>
<?php snippet('palette', array('color' => $color)); ?>
<?php echo $color; ?>

```

Where my ‘palette’ snippet contains this:

```
<?php $color = "now is red"; ?>

```

I want the echo in the template to return “now is red”, but it keeps on giving me “used to be black”. I tried using `global` before variables in many different ways, but I couldn’t succeed.

---

_[View the full topic](https://forum.getkirby.com/t/undefined-variable-in-snippet/321)._
