Search code examples
mediawiki

MediaWiki : #arraymap doesn't work in a model call


I have this array : courant : Gothique,Néo-roman,Ottonien

I tried to use this #arraymap to change its form :

{{#if: {{{courant|}}} |
{{#vardefine:num|0}}
{{#arraymap:{{{courant|}}}|,|@@@|{{#vardefine:num|{{#expr:{{#var:num}}+1}}}}<nowiki>|</nowiki>courant{{#var:num}}=@@@|\n}}
|}}

When I just print it in a <p> balise, it shows this (which is perfect): |courant1=Gothique|courant2=Néo-roman|courant3=Ottonien

But when I put it there :

{{Bouton_recherche_avancée
|pays={{{pays|}}}
|ville={{{ville|}}}
|quartier={{{quartier|}}}
|sous-quartier={{{sous-quartier|}}}
|rue={{{rue|}}}
|personne={{{personne|}}}
|source={{{source|}}}
|structure={{{structure|}}}
|{{#if: {{{courant|}}} |
{{#vardefine:num|0}}
{{#arraymap:{{{courant|}}}|,|@@@|{{#vardefine:num|{{#expr:{{#var:num}}+1}}}}<nowiki>|</nowiki>courant{{#var:num}}=@@@|\n}}
|}}
|date_début={{{date_début|}}}
|date_fin={{{date_fin|}}}
|type_événement={{{type|}}}
|mh={{{mh|}}}
|ismh={{{ismh|}}}
|acr={{{acr|}}}
|unesco={{{unesco|}}}
}}

It does not show anything (maybe it's related to the in some way)

Here's where the code is from : Modèle:Recherche avancée Here's where I want to use it : Recherche avancée and here's what it's trying to call : Modèle:Bouton-recherche-avancée

if you have any on how to make this work or how I can do it in an other way than #arraymap that makes me avoid


Solution

  • I have found myself a solution. I let go of the dream of having a loop and did the lazy method :

    {{Bouton_recherche_avancée
    |text1=Afficher en liste
    |pays={{{pays|}}}
    |ville={{{ville|}}}
    |quartier={{{quartier|}}}
    |sous-quartier={{{sous-quartier|}}}
    |rue={{{rue|}}}
    |personne={{{personne|}}}
    |source={{{source|}}}
    |structure={{{structure|}}}
    |courant1={{#if:{{#explode:{{{courant|}}}|,|0|}}|{{#explode:{{{courant|}}}|,|0|}}}}
    |courant2={{#if:{{#explode:{{{courant|}}}|,|1|}}|{{#explode:{{{courant|}}}|,|1|}}}}
    |courant3={{#if:{{#explode:{{{courant|}}}|,|2|}}|{{#explode:{{{courant|}}}|,|2|}}}}
    |courant4={{#if:{{#explode:{{{courant|}}}|,|3|}}|{{#explode:{{{courant|}}}|,|3|}}}}
    |courant5={{#if:{{#explode:{{{courant|}}}|,|4|}}|{{#explode:{{{courant|}}}|,|4|}}}}
    |courant6={{#if:{{#explode:{{{courant|}}}|,|5|}}|{{#explode:{{{courant|}}}|,|5|}}}}
    |courant7={{#if:{{#explode:{{{courant|}}}|,|6|}}|{{#explode:{{{courant|}}}|,|6|}}}}
    |courant8={{#if:{{#explode:{{{courant|}}}|,|7|}}|{{#explode:{{{courant|}}}|,|7|}}}}
    |courant9={{#if:{{#explode:{{{courant|}}}|,|8|}}|{{#explode:{{{courant|}}}|,|8|}}}}
    |date_début={{{date_début|}}}
    |date_fin={{{date_fin|}}}
    |type_événement={{{type|}}}
    |mh={{{mh|}}}
    |ismh={{{ismh|}}}
    |acr={{{acr|}}}
    |unesco={{{unesco|}}}
    }}
    

    but now it works and there shoudn't be more than 9 courant