mediawikimediawiki-templateswikitext

Passing a pipe in a template call


I'm attempting to call a template from within a template. The value of the parameter I'm passing contains a forward slash and I want to replace that slash with a pipe so that it divides the value into two parameters.

For instance, |nrs_reference=RS38/4 and I want to pass it as {{Sasines full|RS38|4}}, so the RS38 is {{{1}}} and the 4 is {{{2}}}.

But what I'm getting with this code is RS38|4 as {{{1}}}.

{{#if: {{{citation_template|}}}
    |{{#ifeq:{{{citation_template|}}}|NLS full
        |* {{NLS full|title={{{nls_title|}}}|id={{{nls_id|}}}|collection={{{nls_collection|}}}|url={{{nls_url|}}}}}
    |{{#ifeq:{{{citation_template|}}}|Sasines full
        |* {{Sasines full|{{#replace:{{{nrs_reference|}}}|/|{{!}}}}}}
        |* {{#if:{{{citation_template_parameter|}}}|{{{{{citation_template|}}}|{{{citation_template_parameter|}}}={{{citation_template_parameter_value|}}}}}
        |{{#if:{{{volume|}}}|{{{{{citation_template|}}}|volume={{{volume|}}}}}
        |{{{{{citation_template|}}}}}
        }}
        }}
        }}
        }}{{#set: Has citation template=Template:{{{citation_template|}}}}}
            |{{#if: {{{full_citation|}}}|* {{{full_citation|}}}}}
}}

I've tried {{Sasines full|{{#replace:{{{nrs_reference|}}}|/||}}}} also and I get the same results.

Is there another way to accomplish this?

Thanks.


Solution

  • You can use {{#explode:}}:

    {{Sasines full
    <!-- Split nrs_reference by "/" and takes the first fragment -->
    |{{#explode:{{{nrs_reference|}}}|/|0}}
    <!-- Split nrs_reference by "/" and takes the second fragment -->
    |{{#explode:{{{nrs_reference|}}}|/|1}}
    }}
    

    Your attempts didn't work because the pipe inside the returned value of {{#replace:}} is not treated as a delimiter of Sasines full's arguments, but a plain pipe character.