Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Is this possible? txp:evaluate between this value and this value
I currently have this code:
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115'>
What I would really like is > 115
AND < 145
in the same query (if img-aspect-number
is greater than 115 but smaller than 145, do this), so that I won’t need to make intricate IF/ELSE statements.
I can’t figure out how to do this… Is it possible?
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: Is this possible? txp:evaluate between this value and this value
This may work or it may produce double results in the 2nd evaluate.
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115'>
do something
<txp:else />
<txp:evaluate query='<txp:variable name="img-aspect-number" /> < 145'>
do something else
</txp:evaluate>
</txp:evaluate>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Offline
Re: Is this possible? txp:evaluate between this value and this value
colak wrote #331116:
This may work or it may produce double results in the 2nd evaluate.
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115'>...
Thanks, Yiannis!
Actually similar to what I had:
<txp:evaluate query='<txp:variable name="img-aspect-number" /> < 100'>
OPTION
<txp:else />
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 145'>
OPTION
<txp:else />
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115'>
OPTION
<txp:else />
OPTION
</txp:evaluate>
</txp:evaluate>
</txp:evaluate>
But it gets complicated. Especially if you want to add layers…
Last edited by Kjeld (2021-07-24 10:20:53)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: Is this possible? txp:evaluate between this value and this value
etc wrote #331117:
You’ve said it:
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115 and <txp:variable name="img-aspect-number" /> < 145'>...
Absolutely perfect! Tried it right away, and it works exactly as advertised.
It is now wonderfully easy to add layers.
When I saw your code, I thought you got be kidding me. I thought I had tried everything, but I guess not this one…
Thank you very much, Oleg!
Last edited by Kjeld (2021-07-24 10:21:56)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: Is this possible? txp:evaluate between this value and this value
Kjeld wrote #331120:
Absolutely perfect! Tried it right away, and it works exactly as advertised.
It is now wonderfully easy to add layers.
When I saw your code, I thought you got be kidding me. I thought I had tried everything, but I guess not this one…
Thank you very much, Oleg!
Glad it worked out. Could you post your code here for learning purposes?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Is this possible? txp:evaluate between this value and this value
colak wrote #331121:
Glad it worked out. Could you post your code here for learning purposes?
I use the queries to deliver different classes according to the image aspect ratio of the image (horizontal, square, vertical broad, vertical narrow).
For right now it is as follows, but I will finetune this as the site grows:
<txp:evaluate query='<txp:variable name="img-aspect-number" /> < 100'>
OPTION
</txp:evaluate>
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 100 and <txp:variable name="img-aspect-number" /> < 115'>
OPTION
</txp:evaluate>
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115 and <txp:variable name="img-aspect-number" /> < 145'>
OPTION
</txp:evaluate>
<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 145'>
OPTION
</txp:evaluate>
I guess I should really also include “equal to” (=
) to a few of these…
A (far too) detailed explanation of how I calculate and implement the image aspect ratio calculation on my site can be found here.
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Offline
Re: Is this possible? txp:evaluate between this value and this value
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: Is this possible? txp:evaluate between this value and this value
colak wrote #331121:
Glad it worked out. Could you post your code here for learning purposes?
Yiannis, let me know if my explanations above and in the link were too detailed. I can put a simplified explanation here if you like.
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: Is this possible? txp:evaluate between this value and this value
Hi Kjeld,
Sorry I did not acknowledge. It took me some time to mentally put it all together but it’s actually all very clear.
Thanks!
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Is this possible? txp:evaluate between this value and this value
colak wrote #331130:
Hi Kjeld,
Sorry I did not acknowledge. It took me some time to mentally put it all together but it’s actually all very clear.Thanks!
Wonderful.
I fear that combining the explanation for preventing Cumulative Layout Shift with the explanation for a layout that can change according to the image ratio was not a very good idea.
But I connected the two methods on my site, so that is how it came out…
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline