View Single Post
Old 05-07-2023, 05:53 PM   #619
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,480
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Also, a related question:

I have two identifiers, ao3 and ffnet. I'd like to change the order their links appear depending on the publisher.

Here's what I have:

Code:
program:
	list_join(
		 ', ',

## trimmed out other lines for length

		switch_if(
			$publisher=='Archive of Our Own', urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 1),
			$publisher=='FanFiction.net', urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 1),
			''
		), ',',

		switch_if(
			!$publisher=='Archive of Our Own', urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 1),
			!$publisher=='FanFiction.net', urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 1),
			''
		), ',',

	)

This gets the result I want:
- if both ids are available, both are listed
- If publisher is Archive of Our Own, the ao3 link appears first.
- If publisher is FanFiction.net, the ffnet link appears first.

But is this the best way to do this?
You shouldn't need to duplicate the switch_if. I haven't tried to run this template but it should produce what you want:
Code:
program:
	list_join(
		 ', ',

## trimmed out other lines for length

		if $publisher=='Archive of Our Own' then urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 1) fi,
		 ', ',

		if !$publisher=='FanFiction.net' then  urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 1) fi,
		 ',',
	)
chaley is offline   Reply With Quote