Using variables in dpl code

Using variables in dpl code

Hi Will,

I'm trying to play with some templates but I'm hitting a wall there. Is there a specific reason why I cannot use variables (I think that's what we call the {{{stuff}}} construction) in dpl code?

More specifically, I would like to create a template that would list me some pages depending on some variables, so instead of typing

<dpl>
titlematch=MATH110/003/%
</dpl>

I want to type

<dpl>
titlematch={{{course_name}}}/{{{section_number}}}/%
</dpl>

But when I do this (and then use the template elsewhere and specify the values of the variables), I just get a dpl error (and I did check that the values that I'm trying to input in the code do give me the good result if I just input them by hand.

Any ideas?

David Kohler21:19, 11 January 2011

Hi David,

I was away from the office this afternoon - I'll take a closer look at this tomorrow (Wed) to see if I can come up with anything.

Cheers,

-Will, WikiAdministrator02:05, 12 January 2011
 

Hi David,

I finally figured this out - normally, MediaWiki executes the DPL code before it calls the variables. However, DPL has a parser function which allows it to call the variables in the wiki markup before being handed over to the dpl extension. Parser functions look like templates which start with a hash tag - #. So, for your example above, the proper code for the DPL parser function would be:

{{#dpl:
|titlematch={{{course_name}}}/{{{section_number}}}/% 
|namespace=Course
}}

Please let me know if that makes sense or if I can clarify anything. Here's a link to the relevant part of the dpl manual if you would like to look at the syntax in more depth. I also created a test template at Template:DPLtest if you want to test this out.

Cheers,

-Will, WikiAdministrator20:22, 17 January 2011
 

Hi Will,

Awesome, this is exactly it. It does make a lot of sense now that I see the code. I'll let you know what I come up with as a course banner and I'm sure that you guys can make it even better.

Many thanks for the precious help,

David Kohler06:48, 18 January 2011