# How to add a varibale that can be access on the documents templates

**URL:** <https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [19. November 2018 um 08:26 UTC](https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524 "2018-11-19T08:26:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabengwa](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kabengwa](https://forum.shopware.com/u/kabengwa)\
**Post date:** [19. November 2018 um 08:26 UTC](https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524/1 "2018-11-19T08:26:47Z")

</div>

Hello, I would like to know how to create a variable that can be accessed in the documents template. I want to create a template that has items from more than one order,&nbsp; so I wanted to do all the sorting in the controller and then create a variable that can be sent or accessed int he documents template like the {$Order} and other variables are. I saw the tutorial on [creating global variables](https://developers.shopware.com/developers-guide/global-variables-in-templates/) and I followed it well, however it can create a variable that can be found in the frontend templates of the theme but not the document templates. i also cannot use the {debug} on documents to see if the varibales&nbsp;are shown anywhere. When i&nbsp;use {$custom\_variable|print\_r} to try and display the contents of the custom variable&nbsp;i&nbsp;only get a response of 1. so I wanted to ask if what I want to do is possible or there is a better way of doing this?&nbsp;

Any help is much welcome.&nbsp;

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![ansarhusain](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@ansarhusain](https://forum.shopware.com/u/ansarhusain)\
**Post date:** [21. November 2018 um 12:48 UTC](https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524/2 "2018-11-21T12:48:23Z")

</div>

You can add varrible like that for template&nbsp;

$view-\>assign(‘someCustomVar’,‘xxxxxx’);

---

<div class="post-metadata">

**Author:** ![kabengwa](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kabengwa](https://forum.shopware.com/u/kabengwa)\
**Post date:** [21. November 2018 um 14:39 UTC](https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524/3 "2018-11-21T14:39:17Z")

</div>

> [@ansarhusain schrieb:](https://forum.shopware.com/profile/29873/ansarhusain "ansarhusain")
> 
> You can add varrible like that for template&nbsp;
> 
> $view-\>assign(‚someCustomVar‘,‚xxxxxx‘);

i have already tried this inside a controller and also inside a class that i created to create documents. Or maybe i am just putting in the wrong files.&nbsp; &nbsp;

---

<div class="post-metadata">

**Author:** ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)\
**Post date:** [21. November 2018 um 14:40 UTC](https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524/4 "2018-11-21T14:40:51Z")

</div>

This is a short example on how to add addional information to documents via plugin:&nbsp;[GitHub - mnaczenski/MNAddDocumentImages](https://github.com/mnaczenski/MNAddDocumentImages)

---

<div class="post-metadata">

**Author:** ![kabengwa](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kabengwa](https://forum.shopware.com/u/kabengwa)\
**Post date:** [22. November 2018 um 08:55 UTC](https://forum.shopware.com/t/how-to-add-a-varibale-that-can-be-access-on-the-documents-templates/56524/5 "2018-11-22T08:55:00Z")

</div>

> [@Moritz Naczenski schrieb:](https://forum.shopware.com/profile/14574/Moritz%20Naczenski "Moritz%20Naczenski")
> 
> This is a short example on how to add addional information to documents via plugin:&nbsp;[https://github.com/mnaczenski/MNAddDocumentImages](https://github.com/mnaczenski/MNAddDocumentImages)

Thank you very much. that example worked wonders for me.&nbsp; I was getting it wrong from here.&nbsp;

```
'Shopware_Components_Document::assignValues::after'

```

&nbsp;
