Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
 
Correct syntax for variable output multiple times
I’m calculating a variable from another variable & evaluate, like this:
<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query='<txp:variable name="day" /> - 264' />' />
This works in so far as it outputs the correct number. All good there. I cannot output that variable an additional time, including immediately afterwards.
Given the working code above, I expected the following to output the variable twice:
<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query='<txp:variable name="day" /> - 264' />' />
<txp:variable name="days_into_dark" output="1" />
The second line has no effect, and I’m confused as to why not. What am I doing wrong?
Thank you.
Offline
Re: Correct syntax for variable output multiple times
Try the second one without the output attribute? That usually spits the value out for me.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Correct syntax for variable output multiple times
Bloke wrote #341076:
Try the second one without the
outputattribute? That usually spits the value out for me.
Thanks, Bloke. No dice. Same result. I’m a bit baffled.
Here’s the whole scaffold:
<txp:variable name="day" trim="1">
  <txp:date time="now" format="%j" />
</txp:variable>
<txp:evaluate query='<txp:variable name="day" /> > 80 and <txp:variable name="day" /> < 264'>
  Days until Dark: <txp:variable name="days_until_dark" output="1" value='<txp:evaluate query='264 - <txp:variable name="day" />' />' />
  Days into Light:
<txp:else />
  Days until Light:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
	<txp:variable name="days_until_light" output="1" value='<txp:evaluate query='80 - <txp:variable name="day" />' />' />
  <txp:else />
	<txp:variable name="days_until_light" output="1" value='<txp:evaluate query='365 + 80 - <txp:variable name="day" />' />' />
  </txp:evaluate>
  Days into Dark:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
	<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query='101 + <txp:variable name="day" />' />' />
	<txp:variable name="days_into_dark" />
  <txp:else />
	<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query='<txp:variable name="day" /> - 264' />' />
	<txp:variable name="days_into_dark" />
  </txp:evaluate>
</txp:evaluate>
I’ll grab a tag trace for the next post.
Offline
Re: Correct syntax for variable output multiple times
Tag trace excerpt:
	 28.16 |     0.09 | 	<txp:evaluate query='<txp:variable name="day" /> > 80 and <txp:variable name="day" /> < 264'>
	 28.16 |     0.02 | 		[attribute 'query']
	 28.16 |          | 			[true]
	 28.17 |     0.01 | 			<txp:variable name="day" />
	 28.18 |     0.00 | 			<txp:variable name="day" />
	 28.18 |          | 		[/attribute]
	 28.24 |          | 		[false]
	 28.25 |          | 	</txp:evaluate>
	 28.25 |     0.11 | 	<txp:evaluate query='<txp:variable name="day" /> > 80 and <txp:variable name="day" /> < 264'>
	 28.25 |     0.01 | 		[attribute 'query']
	 28.25 |          | 			[true]
	 28.25 |     0.00 | 			<txp:variable name="day" />
	 28.26 |     0.00 | 			<txp:variable name="day" />
	 28.26 |          | 		[/attribute]
	 28.27 |          | 		[false]
	 28.27 |     0.05 | 		<txp:evaluate query='<txp:variable name="day" /> < 80'>
	 28.28 |     0.01 | 			[attribute 'query']
	 28.28 |          | 				[true]
	 28.28 |     0.00 | 				<txp:variable name="day" />
	 28.29 |          | 			[/attribute]
	 28.29 |          | 			[false]
	 28.29 |     0.02 | 			<txp:evaluate query='365 + 80 - <txp:variable name="day" />' />
	 28.30 |     0.01 | 				[attribute 'query']
	 28.30 |          | 					[true]
	 28.30 |     0.00 | 					<txp:variable name="day" />
	 28.31 |          | 				[/attribute]
	 28.32 |          | 		</txp:evaluate>
	 28.32 |     0.04 | 		<txp:evaluate query='<txp:variable name="day" /> < 80'>
	 28.32 |     0.01 | 			[attribute 'query']
	 28.32 |          | 				[true]
	 28.32 |     0.00 | 				<txp:variable name="day" />
	 28.33 |          | 			[/attribute]
	 28.33 |          | 			[false]
	 28.33 |     0.02 | 			<txp:evaluate query='<txp:variable name="day" /> - 264' />
	 28.34 |     0.01 | 				[attribute 'query']
	 28.34 |          | 					[true]
	 28.34 |     0.00 | 					<txp:variable name="day" />
	 28.35 |          | 				[/attribute]
	 28.35 |     0.01 | 			<txp:variable name="days_into_dark" />
	 28.36 |          | 				[<txp:variable>: Unknown variable 'days_into_dark']
	 28.36 |          | 		</txp:evaluate>
	 28.36 |          | 	</txp:evaluate>
	 28.36 |     0.01 | 	<txp:variable name='days_into_dark' output='1' />
	 28.37 |     0.01 | 	<txp:variable name="days_into_dark" output="1" />
	 28.38 |     0.01 | 	<txp:date time="now" format="%j" />
					Offline
Re: Correct syntax for variable output multiple times
Hmmm. I pasted your code in and got values for both:
Days until Light: 139 Days into Dark: 42
Is that not what you’re expecting?
Just a thing about the value attribute when setting a variable. To save apostrophe hell with tags in attributes, you can set the value via the container instead.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Correct syntax for variable output multiple times
Bloke wrote #341079:
Hmmm. I pasted your code in and got values for both:
Days until Light: 139 Days into Dark: 42
Is that not what you’re expecting?
Not quite. These two lines:
<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query='<txp:variable name="day" /> - 264' />' />
<txp:variable name="days_into_dark" />
…if I’m understanding correctly, the first line defines the variable & outputs it, and the second should just output it – but it doesn’t (with or without output). So the output should be:
Days until Light: 139 Days into Dark: 42 42
Just a thing about the
valueattribute when setting a variable. To save apostrophe hell with tags in attributes, you can set the value via the container instead.
Thank you. I’m on the case with this now, I’m stripping it down and factoring in leap years so I can set it and forget it.
Last edited by gaekwad (Yesterday 20:35:51)
Offline
Re: Correct syntax for variable output multiple times
I can only assume that the output is immediately returning the value and not assigning it to the variable. That might be why.
If you remove the first output in the assignment then you should be able to display the value after.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Correct syntax for variable output multiple times
Bloke wrote #341081:
I can only assume that the
outputis immediately returning the value and not assigning it to the variable. That might be why.If you remove the first
outputin the assignment then you should be able to display the value after.
That makes good sense – thank you, Bloke.
Offline
Re: Correct syntax for variable output multiple times
You are bitten by the dreaded quotes-in-quotes issue, attenuated by the second pass:
<txp:variable name="day" trim="1">
  <txp:date time="now" format="%j" />
</txp:variable>
<txp:evaluate query='<txp:variable name="day" /> > 80 and <txp:variable name="day" /> < 264'>
  Days until Dark: <txp:variable name="days_until_dark" output="1" value='<txp:evaluate query=''264 - <txp:variable name="day" />'' />' />
  Days into Light:
<txp:else />
  Days until Light:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
	<txp:variable name="days_until_light" output="1" value='<txp:evaluate query=''80 - <txp:variable name="day" />'' />' />
  <txp:else />
	<txp:variable name="days_until_light" output="1" value='<txp:evaluate query=''365 + 80 - <txp:variable name="day" />'' />' />
  </txp:evaluate>
  Days into Dark:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
	<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query=''101 + <txp:variable name="day" />'' />' />
	<txp:variable name="days_into_dark" />
  <txp:else />
	<txp:variable name="days_into_dark" output="1" value='<txp:evaluate query=''<txp:variable name="day" /> - 264'' />' />
	<txp:variable name="days_into_dark" />
  </txp:evaluate>
</txp:evaluate>
					Offline
Re: Correct syntax for variable output multiple times
etc wrote #341083:
You are bitten by the dreaded quotes-in-quotes issue, attenuated by the second pass:
One way to simplify that is to use txp:variable as a container tag:
<txp:date time="now" format="%j" variable="day" />
<txp:evaluate query='<txp:variable name="day" /> > 80 and <txp:variable name="day" /> < 264'>
  Days until Dark: <txp:variable name="days_until_dark" output><txp:evaluate query='264 - <txp:variable name="day" />' /></txp:variable>
  Days into Light:
<txp:else />
  Days until Light:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
    <txp:variable name="days_until_light" output><txp:evaluate query='80 - <txp:variable name="day" />' /></txp:variable>
  <txp:else />
    <txp:variable name="days_until_light" output><txp:evaluate query='365 + 80 - <txp:variable name="day" />' /></txp:variable>
  </txp:evaluate>
  Days into Dark:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
    <txp:variable name="days_into_dark" output><txp:evaluate query='101 + <txp:variable name="day" />' /></txp:variable>
    <txp:variable name="days_into_dark" />
  <txp:else />
    <txp:variable name="days_into_dark" output><txp:evaluate query='<txp:variable name="day" /> - 264' /></txp:variable>
    <txp:variable name="days_into_dark" />
  </txp:evaluate>
</txp:evaluate>
and if you’re not hell-bent on outputting the first instance as well, then you can use the variable attribute immediately in txp:evaluate to assign the tag’s output to a variable:
<txp:date time="now" format="%j" variable="day" />
<txp:evaluate query='<txp:variable name="day" /> > 80 and <txp:variable name="day" /> < 264'>
  Days until Dark: <txp:evaluate variable="days_until_dark" query='264 - <txp:variable name="day" />' />
<txp:variable name="days_until_dark" />
  Days into Light:
<txp:else />
  Days until Light:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
    <txp:evaluate variable="days_until_light" query='80 - <txp:variable name="day" />' />
    <txp:variable name="days_until_light" />
  <txp:else />
    <txp:evaluate variable="days_until_light" query='365 + 80 - <txp:variable name="day" />' />
    <txp:variable name="days_until_light" />
  </txp:evaluate>
  Days into Dark:
  <txp:evaluate query='<txp:variable name="day" /> < 80'>
    <txp:evaluate variable="days_into_dark" query='101 + <txp:variable name="day" />' />
    <txp:variable name="days_into_dark" />
  <txp:else />
    <txp:evaluate variable="days_into_dark" query='<txp:variable name="day" /> - 264' />
    <txp:variable name="days_into_dark" />
  </txp:evaluate>
</txp:evaluate>
					TXP Builders – finely-crafted code, design and txp
Offline