FANDOM


  • I'm making a template to list the appearances of characters on Broadchurch Wiki which uses #switches to determine if each episode includes a character per series (so that each variable can accept a variety of inputs including yes, Yes, true, etc.). What I want to be able to do is if the result from all those #switches is blank, meaning that a character hasn't appeared at all in a series, a message saying that the character doesn't appear is written instead of just leaving that section blank. Is there a parser function I can use to wrap 8 separate #switch functions in to determine if their combined result is nothing and, if so, display a line of text? I know how to do this with single values, but not multiple parser functions. Thanks!

      Loading editor
    • Using {{#if: should work http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23if Add this after the #switch function

      {{#if: {{{Episode 1.1|}}}{{{Episode 1.2|}}}{{{Episode 1.3|}}}{{{Episode 1.4|}}}{{{Episode 1.5|}}}{{{Episode 1.6|}}}{{{Episode 1.7|}}}{{{Episode 1.8|}}} | | * No appearances in Series 1}}
      
        Loading editor
    • Thanks for that. It does seem to work part way, as in that works when people leave all the non-episode spots blank, but the code is meant to work so that it also accepts no, No, False, and false, which can make the list easier to read in an ongoing series (unaired episodes are blank while aired ones have a word declaring their position). Is there any way to organise this using the results of the #switch functions?

        Loading editor
    • Bump. As I said, I'm looking to see if there's a solution which uses the results of the #switches after they've already evaluated the variables, and if the value of all of the #switches combined is an empty string, then show the desired text string. See w:c:broadchurch:Template:Character_appearances/test.

        Loading editor
    • I understand why you have so many variables... but it makes the source mode look confusing with a mixture of Yes and yes and true and True.

      {{Character appearances
       | Episode 1.1   = 
       | Episode 1.2   = 
       | Episode 1.3   = 
       | Episode 1.4   = 
       | Episode 1.5   = 
       | Episode 1.6   = 
       | Episode 1.7   = 
       | Episode 1.8   = 
       | Episode 2.1   = Yes
       | Episode 2.2   = yes
       | Episode 2.3   = true
       | Episode 2.4   = True
       | Episode 2.5   = 
       | Episode 2.6   = 
       | Episode 2.7   = 
       | Episode 2.8   = 
      }}
      

      If I was designing the template, I would limit variables to appeared, did not appear or incorrect answer.

      {{#switch:{{{Episode 1.1|no}}} |yes = 
      * [[Episode 1.1]] |no = |#default = * ''please answer yes or no'' }}
      

      With "no" set as default, the "No appearances in Series" message is displayed until a "yes" episode switches it off.

      {{#switch: {{{Episode 1.1|no}}} {{{Episode 1.2|no}}} {{{Episode 1.3|no}}} {{{Episode 1.4|no}}} {{{Episode 1.5|no}}} {{{Episode 1.6|no}}} {{{Episode 1.7|no}}} {{{Episode 1.8|no}}} 
      | no no no no no no no no = * no appearances in Series 1 }}
      

      Source mode ignores pre-set answers so it shows, as you posted above, unaired episodes are blank while aired ones have a word declaring their position.

      {{Character appearances
      |Episode 1.1 = yes
      |Episode 1.2 = yes
      |Episode 1.3 = no
      |Episode 1.4 = yes
      |Episode 1.5 = 
      |Episode 1.6 = 
      |Episode 1.7 = 
      |Episode 1.8 = 
      }}
      
        Loading editor
    • Thanks for the help. It's nearly working! However, it's not automatically using the "no" response when none is stated (see w:c:broadchurch:Template:Character_appearances/test). If either "yes" or "no" is stated for all variables, the template works as intended. However, if any are left blank, the 'Please answer "yes" or "no"' result is shown. Have I done something wrong there?

        Loading editor
    • So you want the message 'Please answer "yes" or "no"' to only appear if none of the episodes are listed?

        Loading editor
    • No, I want that message to appear if a person has put in a value other than yes, no, or blank, to tell them to do so. If none of the episodes have yes beside them (so they have either no or blank), then I want to have the line "No appearances in Series 1" appear in the space where the links to the episodes would have appeared if any of the values were yes.

        Loading editor
    • When you posted "aired episodes have a word declaring their position" I understood to mean that when an episode is aired the episode HAD to have either yes or no against its name...

      {{Character appearances
       | Episode 1.1   = <!-- aired enter yes or no --> no
       | Episode 1.2   = <!-- aired enter yes or no --> no
       | Episode 1.3   = <!-- aired enter yes or no --> no
       | Episode 1.4   = <!-- aired enter yes or no --> yes
       | Episode 1.5   = <!-- aired enter yes or no --> yes
       | Episode 1.6   = <!-- aired enter yes or no --> yes
       | Episode 1.7   = <!-- aired enter yes or no --> yes
       | Episode 1.8   = <!-- aired enter yes or no --> no
       | Episode 2.1   = <!-- not aired leave blank -->
       | Episode 2.2   = <!-- not aired leave blank -->
       | Episode 2.3   = <!-- not aired leave blank -->
       | Episode 2.4   = <!-- not aired leave blank -->
       | Episode 2.5   = <!-- not aired leave blank -->
       | Episode 2.6   = <!-- not aired leave blank -->
       | Episode 2.7   = <!-- not aired leave blank -->
       | Episode 2.8   = <!-- not aired leave blank -->
      }}
      

      I tested the template using VisualEditor. I used the scenario that Series 2 had not aired so no editing yet. So it uses "the "No appearances in Series 2" message is displayed until a "yes" episode switches it off."

      You are using the syntax template in Source Mode which I had not accommodated for. I have adjusted the template so it can be used this way. It is designed to enter the appearances as the series progresses as detailed above...

      Series 1 Series 2
      • No appearances in Series 2


      {| class="wikitable" 
      ! width=50%| Series 1
      ! width=50%| Series 2
      
      |-
      | {{#if: {{{Episode 1.1|}}} |{{#switch:{{{Episode 1.1|}}} |yes = 
      * [[Episode 1.1]] |no = |#default = * ''please answer yes or no'' }} | * No appearances in [[Series 1]] }}{{#if: {{{Episode 1.2|}}} |{{#switch:{{{Episode 1.2|}}} |yes = 
      * [[Episode 1.2]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 1.3|}}} |{{#switch:{{{Episode 1.3|}}} |yes = 
      * [[Episode 1.3]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 1.4|}}} |{{#switch:{{{Episode 1.4|}}} |yes = 
      * [[Episode 1.4]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 1.5|}}} |{{#switch:{{{Episode 1.5|}}} |yes = 
      * Episode 1.5 |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 1.6|}}} |{{#switch:{{{Episode 1.6|}}} |yes = 
      * Episode 1.6 |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 1.7|}}} |{{#switch:{{{Episode 1.7|}}} |yes = 
      * [[Episode 1.7]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 1.8|}}} |{{#switch:{{{Episode 1.8|}}} |yes = 
      * [[Episode 1.8]] |no = |#default = * ''please answer yes or no'' }} | }} 
      
      | {{#if: {{{Episode 2.1|}}} |{{#switch:{{{Episode 2.1|}}} |yes = 
      * [[Episode 2.1]] |no = * No appearances in Series 2 |#default = * ''please answer yes or no'' }} | * No appearances in Series 2 }}{{#if: {{{Episode 2.2|}}} |{{#switch:{{{Episode 2.2|}}} |yes = 
      * [[Episode 2.2]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 2.3|}}} |{{#switch:{{{Episode 2.3|}}} |yes = 
      * [[Episode 2.3]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 2.4|}}} |{{#switch:{{{Episode 2.4|}}} |yes = 
      * [[Episode 2.4]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 2.5|}}} |{{#switch:{{{Episode 2.5|}}} |yes = 
      * [[Episode 2.5]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 2.6|}}} |{{#switch:{{{Episode 2.6|}}} |yes = 
      * [[Episode 2.6]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 2.7|}}} |{{#switch:{{{Episode 2.7|}}} |yes = 
      * [[Episode 2.7]] |no = |#default = * ''please answer yes or no'' }} | }}{{#if: {{{Episode 2.8|}}} |{{#switch:{{{Episode 2.8|}}} |yes = 
      * [[Episode 2.8]] |no = |#default = * ''please answer yes or no'' }} | }} 
      |}
      
        Loading editor
    • Thanks for your help, but that won't work either, as it defines no appearances as not having appeared in episode 1 of that series, and there are several characters who don't appear until later in each series. Never mind then. I'll just stop trying to overcomplicate this template and keep it simple. "yes" for an appearance, "no" for no appearance. More writing for the end user, but much simpler on the back end. Thanks for all the help you've given!

        Loading editor
    • It might be easier to build this template in Lua instead. In Lua you could just loop over the parameters instead of doing them one by one, and use a simple variable to "remember" whether you already got something.

        Loading editor
    • Huh, I hadn't even thought about using Lua. I'll have a try with that.

        Loading editor
    • http://m.mediawiki.org/wiki/Extension:Variables and http://m.mediawiki.org/wiki/Extension:Loops can give you similar capabilities using standard templates, but you do have to request that they be enabled for your wiki.

        Loading editor
    • OK, so I'm trying to write the Lua needed to go with a reworking of the template, but I'm running into errors I can't figure out how to fix from looking at help pages. There's a problem with the second function here, p.none, in line 14 of the module. It's meant to check to see if the value of each of the 8 frame.args is an empty string by concatenating them together and seeing if the combined value is empty (the string, empty or not, being given to these values via parameters in the template which the modules will be called from, which in turn use values given to it on the page on which that template is transcluded). I kept getting an error upon saving though before I finally told it to accept erroneous code so I could ask for help. I've never written something in Lua before BTW, so I've just been copying the examples found on help pages elsewhere. Any help with identifying where I've gone wrong would be appreciated! (Links to a good Lua tutorial would also be welcomed.)

        Loading editor
    • Yeah, coding in Lua takes a little getting used to. It errors because an if also needs to be closed with end (just like functions)

      if condition then
          -- something
      end

      Anyway, I think you can do both things in one #invoke per series. I've built a module here. See the talk page on how to use it. If you want I can also make it accept Yes, true and True as acceptable values.

      If you need something explained, feel free to ask.

        Loading editor
    • Your version is perfect and you are brilliant! Thank you thank you thank you so much!!!!

        Loading editor
    • A FANDOM user
        Loading editor
Give Kudos to this message
You've given this message Kudos!
See who gave Kudos to this message
Community content is available under CC-BY-SA unless otherwise noted.