# Bug, i can´t add dinamyc templates

**URL:** <https://forum.thegraph.com/t/bug-i-can-t-add-dinamyc-templates/3550>\
**Category:** Questions & Feedback\
**Created:** [September 5, 2022, 5:08pm UTC](https://forum.thegraph.com/t/bug-i-can-t-add-dinamyc-templates/3550 "2022-09-05T17:08:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert22](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@robert22](https://forum.thegraph.com/u/robert22)\
**Post date:** [September 5, 2022, 5:08pm UTC](https://forum.thegraph.com/t/bug-i-can-t-add-dinamyc-templates/3550/1 "2022-09-05T17:08:47Z")

</div>

Hi,

when indexing generate this error and not add template

the code example template in this repo [GitHub - leovafme/thegraph-add-templates](https://github.com/leovafme/thegraph-add-templates)

expected add template of my factory and listing events of others contracts dynamically

Thank you for any information

 ![187925428-909d4f01-0361-43a3-a4af-9bd94d864dc6](https://us1.discourse-cdn.com/flex020/uploads/thegraph1/original/2X/3/3934db923c082b502baa2d2644a2942bf0fc1b00.png)

---

<div class="post-metadata">

**Author:** ![DataNexus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/datanexus/32/1830_2.png) [@DataNexus](https://forum.thegraph.com/u/DataNexus)\
**Post date:** [September 12, 2022, 1:11am UTC](https://forum.thegraph.com/t/bug-i-can-t-add-dinamyc-templates/3550/2 "2022-09-12T01:11:04Z")

</div>

It looks like you may want to select a different id. Since the ExampleEntity id is the signer of the transaction, this can be loaded multiple times. If the `event.params.game` appears more than once it can cause an error trying to initialize that template multiple times.

```auto
export function handleNewExchange(event: NewExchange): void {
  let entity = ExampleEntity.load(event.transaction.from.toHex())
  ...
  entity.save()
  Exchange.create(event.params.game)
}

```

I would consider adding a game entity, and upon creation of the game you invoke the template.

```auto
import { BigInt } from "@graphprotocol/graph-ts"
import { NewExchange } from "../generated/FactoryTest/FactoryTest"
import { Exchange } from "../generated/schema"
import { Exchange as ExchangeTemplate} from '../generated/templates'

export function handleNewExchange(event: NewExchange): void {
let exchange = Exchange.load({exchange_contract_address})

if (!exchange) {
  exchange = new Exchange({exchange_contract_address})
  other fields...
  ExchangeTemplate.create({exchange_contract_address})
}

counter logic etc. 
exchange.save()
}

```
