# Assigning value within ic-statement to variable outside ic-statement

**URL:** <https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129>\
**Category:** Templates\
**Tags:** tax:tech\
**Created:** [July 15, 2021, 2:47pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129 "2021-07-15T14:47:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gianluca](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@Gianluca](https://community.silverfin.com/u/Gianluca)\
**Post date:** [July 15, 2021, 2:47pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129/1 "2021-07-15T14:47:23Z")

</div>

Hi,

I’m having an issue with assigning a value in an ic-statement to a variable that has been created outside that variable.

Here an example of what I am trying to do:

```auto
{% assign testVar = false %}

{{ testVar }}

{% ic %}{% input period.custom.doc.received as:boolean default:testVar assign:testVar %}{% endic %}

{{ testVar }}

```

In edit mode I see “true” for the 2nd variable but in preview I see 2x false. Isn’t it supposed to show ‘true’ the 2nd time since the variable has been created outside the ic-statement? It is like the value is not being assigned.

![Screenshot 2021-07-15 at 16.46.40](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/8/89677291c6ff2b4f6947ce15b2984abe908d01b9.png)  
 ![Screenshot 2021-07-15 at 16.47.11](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/5/5aaed187bb51145ea7720983be73932129e9b576.png)

Thanks!

Best regards,  
Gianluca

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [July 15, 2021, 2:55pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129/2 "2021-07-15T14:55:51Z")

</div>

Hi @Gianluca,

I can simulate your issue, as if I reproduce your code, your boolean value will have the value `false` (as your first var is created no matter what).

Your second var `testVar` however, will only be created in input-mode however, which is the issue you’re facing ☝

but you have to watch out with coding like this. I’d advise you to always create vars outside IC-tags. Yes, that means an extra line of coding in this case, as you cannot use the assign attribute as that would mean the creation of the variable (that has to work, no matter IC or NIC) is only done in input-mode:

```auto
{% comment %}create needed vars{% endcomment %}
{% assign doc_received = period.custom.doc.received | default:false %}

{% ic %}{% input period.custom.doc.received as:boolean default:false %}{% endic %}

{{ doc_received }} 

```

Also, keep the naming of vars limited to just small letters (see [here](https://developer.silverfin.com/docs/liquid-specific-topics#naming-variables) our guidelines about that); just a tip though 😉

---

<div class="post-metadata">

**Author:** ![Gianluca](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@Gianluca](https://community.silverfin.com/u/Gianluca)\
**Post date:** [July 15, 2021, 3:24pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129/3 "2021-07-15T15:24:05Z")

</div>

Hi @sven

Thanks for your quick reply! Your code is working but I’m not sure what the difference is with mine?  
I see you are using the value of the global variable, in the local variable instead of “assign” but the outcome is the same, no? Isn’t it supposed to work how I did it?

Thanks!

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [July 15, 2021, 3:42pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129/4 "2021-07-15T15:42:37Z")

</div>

No, because your assign statement is done within IC-tags, meaning the var testVar will be created only in input-mode.  
If you then export the template (export mode), that variable isn’t created anymore.

This would be fine:

```auto
{% input period.custom.doc.received as:boolean default:false assign:doc_received %}

```

as it gets created always (so not just in IC mode).

This however:

```auto
{% ic %}{% input period.custom.doc.received as:boolean default:false assign:doc_received %}{% endic %}

```

will only work in IC-mode as your assign-statement is done in IC-mode. Hence, you cannot really use that assign within the input-statement IF that input-tag is also between IC-tags.

Hope that clarifies it; if not, don’t shy away to ask 🙂

---

<div class="post-metadata">

**Author:** ![Gianluca](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@Gianluca](https://community.silverfin.com/u/Gianluca)\
**Post date:** [July 15, 2021, 3:47pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129/5 "2021-07-15T15:47:31Z")

</div>

Alright thanks for the explanation! 🙂

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [July 16, 2021, 1:01pm UTC](https://community.silverfin.com/t/assigning-value-within-ic-statement-to-variable-outside-ic-statement/2129/6 "2021-07-16T13:01:44Z")

</div>


