Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-07-24 04:38:30

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

#2 2021-07-24 05:11:38

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

#3 2021-07-24 08:25:25

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Is this possible? txp:evaluate between this value and this value

Kjeld wrote #331115:

I can’t figure out how to do this… Is it possible?

You’ve said it:

<txp:evaluate query='<txp:variable name="img-aspect-number" /> > 115 and <txp:variable name="img-aspect-number" /> < 145'>

Offline

#4 2021-07-24 10:13:26

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

#5 2021-07-24 10:17:35

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

#6 2021-07-24 10:45:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

#7 2021-07-24 11:00:36

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

#8 2021-07-24 18:35:40

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Is this possible? txp:evaluate between this value and this value

Kjeld wrote #331122:

I guess I should really also include “equal to” (=) to a few of these…

Greater/less or equal (resp. >= and <=) work just fine.

Offline

#9 2021-07-25 01:10:59

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

Re: Is this possible? txp:evaluate between this value and this value

etc wrote #331124:

Greater/less or equal (resp. >= and <=) work just fine.

Thank you, Oleg.


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

#10 2021-07-25 01:12:37

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

#11 2021-07-25 04:15:11

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

#12 2021-07-25 05:39:09

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 446
Website

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

Board footer

Powered by FluxBB