If...then...else...endif -- and...or

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

If...then...else...endif -- and...or

1marc1
Hi Team,

I am not sure how difficult it would be to implement, but it would be very useful to have the ability to do something like this:

:myvar: blue
ifeval::[ "{myvar}" == "blue" OR "{myvar}" == "red" ]
This is for categories that are blue or red.
else::[]
This is for categories that are not blue or red
endif::[]

At the moment, I believe the only way to achieve the above is by doing:

:myvar: blue
ifeval::[ "{myvar}" == "blue" ]
This is for categories that are blue or red.
endif::[]

ifeval::[ "{myvar}" == "red" ]
This is for categories that are blue or red.
endif::[]

ifeval::[ "{myvar}" != "blue" ]
ifeval::[ "{myvar}" != "red" ]
This is for categories that are not blue.
endif::[]
endif::[]

Marc
Reply | Threaded
Open this post in threaded view
|

Re: If...then...else...endif -- and...or

David Jencks
I didn’t try this, but I’d expect something like this might work:

ifeval::["{myvar}" == “blue”]
:myvarblue: yes
endif::[]

feval::["{myvar}" == “red”]
:myvarred: yes
endif::[]

:myvarblueorred: {myvarblue}{myvarred}

ifeval::[ “{myvarblueorred}” != “” ]
This is for categories that are blue or red.
endif::[]

ifeval::[ “{myvarblueorred}” ==“” ]
This is for categories that are neither blue nor red
endif::[]

“AND” could be done similarly (e..g == ‘yeses”)

At this point I have no opinion on whether your suggestion might be a good idea or not, but there might be a slightly less inconvenient workaround  available now.

david jencks

On Feb 13, 2020, at 4:54 PM, 1marc1 [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Hi Team,

I am not sure how difficult it would be to implement, but it would be very useful to have the ability to do something like this:

:myvar: blue
ifeval::[ "{myvar}" == "blue" OR "{myvar}" == "red" ]
This is for categories that are blue or red.
else::[]
This is for categories that are not blue or red
endif::[]

At the moment, I believe the only way to achieve the above is by doing:

:myvar: blue
ifeval::[ "{myvar}" == "blue" ]
This is for categories that are blue or red.
endif::[]

ifeval::[ "{myvar}" == "red" ]
This is for categories that are blue or red.
endif::[]

ifeval::[ "{myvar}" != "blue" ]
ifeval::[ "{myvar}" != "red" ]
This is for categories that are not blue.
endif::[]
endif::[]

Marc


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/If-then-else-endif-and-or-tp7645.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: If...then...else...endif -- and...or

halol
In reply to this post by 1marc1
I would love to see this feature as well. Without it, ifeval is often difficult to use, even if there are workarounds. I tend to use something such as:

For the OR:

:myvar: blue
ifeval::[ "{myvar}" == "blue" ]
:group1:
endif::[]

ifeval::[ "{myvar}" == "red" ]
:group1:
endif::[]

ifdef::group1[]
For blue or red
endif::[]

ifndef::group1[]
For not blue and not red
endif::[]

For the AND:

:myvar1: blue
:myvar2: green
ifeval::[ "{myvar1}" == "blue" ]
ifeval::[ "{myvar2}" == "red" ]
:group2:
endif::[]
endif::[]

ifdef::group2[]
For var1 = blue and var2 = red
endif::[]

and so on.

It is slightly off-topic, but a long-form for ifeval would also be nice if possible.