Template talk:Testbanner

From MEpedia, a crowd-sourced encyclopedia of ME and CFS science and history

-- ~Njt (talk) 08:32, October 29, 2019 (EDT)[edit source | reply | new]

User:Pyrrhus All translations could be added as a system message. A parameter can be passed to set the color and which message to show. Javascript can invoke the banner as before, only when it is needed. Code for common.js, for each category:

//For Potential treatments category
if (wgCategories.includes ("Potential treatments")){
     $(".firstHeading").prepend ('{{testbanner|treatment}}');

// pivot fix
$("h1.title").prepend ('{{testbanner|treatment}}');
}

Classes to add to common.css: green, blue, red background colors. (Once working, edit out the span statements that set colors.) Hope this is helpful. Template:String on page I also just copied from Wikipedia, if you wanted to use it use in a nested if so if not a potential treatment, check if hypothesis, if not hypothesis either check if comorbidity etc... I believe the In cat extension is still "expensive" so not worth installing when we can use Javascript. ~Njt (talk) 08:32, October 29, 2019 (EDT)

This is great, thanks Njt! It may well come in handy. I think the Extension:PageInCat is just a simple database query, not expensive at all, and may come in handy for other purposes. But Javascript is still definitely a viable Plan B. As a general rule, I try to avoid using javascript unless all else fails. Thanks!
Pyrrhus (talk) 13:47, October 29, 2019 (EDT)
Actually, I just tried it and it turns out that you can not call a template from javascript, just html tags, but not wikitext. Trying to call {{testbanner|treatment}} just placed a large "{{testbanner|treatment}}" at the top of the page.
Pyrrhus (talk) 14:57, October 29, 2019 (EDT)
For common.js:
//For Medical hypotheses category
if (wgCategories.includes ("Medical hypotheses")){
//Load contents of template into "response"
$.ajax ("/wiki/Template:Testbanner").done (function (response){

    $(".firstHeading").prepend(response);
//pivot fix 
    $("h1.title").prepend(response);

});
}
This is basically adapted from the code higher up common.js that replaces the pages hits number. See also this code This version would need a different template for each category.
Option 2: Keep the translations in the Javascript example here ~Njt (talk) 16:44, October 29, 2019 (EDT)
Great ideas! Thanks!
Pyrrhus (talk) 21:07, October 29, 2019 (EDT)