Template sensor with attributes - How can I (re)use a variable?

Sorry if it’s a newbie question, none of this is my native language and I’ve been been googeling all day without luck.
How can I set a variable and use it for output as an attribute? For some reason, currentPrice won’t keep its value past the first print in this example:

 #Template:
 #  sensor:
     - name: "test"
       state: >-
         {% set currentPrice = 1234 %}
         {{ currentPrice }}
       attributes:
         some_attribute: >-
           {{ currentPrice }}

Last line doesn’t work - the output is just an empty string:
some_attribute: ''

Not exactly. But you can use self-referencing.

Thank you kindly for your reply!
I realize my example above is a little misleading. State and attribute(s) will not be the same.

#Template:
#  sensor:
    - name: "test"
      state: >-
        {% set morningPrice = 1234 %}
        {% set currentPrice = 5678 %}
        {% set lossYield = currentPrice - morningPrice %}
        {{ lossYield }}
      attributes:
        some_attribute: >-
          {{ currentPrice }}
        other_attribute: >-
          {{ morningPrice }}