Semanticmediawiki: Use of #var in #set

Created on 10 Mar 2016  Â·  14Comments  Â·  Source: SemanticMediaWiki/SemanticMediaWiki

Hello everyone,

I am facing an issue I can't solve by myself. Here below is the code written in a template.

  1. I begin a #while loop (using "i")
    {{ #vardefine: i | 1 }}
  2. I define a few useful #var which will help me to simplify the code
    {{ #vardefine: Point{{ #var: i }} | [[Point::{{{ Point{{ #var: i }} |}}} ]] }}
    {{ #vardefine: Debut | {{{ Troncon{{ #var: i }}_Debut| }}} }}
    {{ #vardefine: Secteur | {{{ Troncon{{ #var: i }}_Secteur| }}} }}
    {{ #vardefine: Troncon_Temp | {{ #var: Point{{ #var: Debut}} }} }}
  3. I begin another #while loop (using "j"), included in the first "i" loop. Troncon_Temp is being updated in this second loop whenever "j" is incremented.
    {{ #vardefine: Troncon_Temp | {{ #var: Troncon_Temp }} – {{ #var_final: Point{{ #var: j }} }} }}
  4. Then, this is where it does not work: mediawiki doesn't understand what I am telling it to do.
    {{ #set: Troncon_{{ #var: Secteur }} = {{ #var: Troncon_Temp }} }}
  5. Because of 4., I can't see the result of course.
    {{ #show: {{PAGENAME}} | ?Troncon_{{ #var: Secteur }} }}

When calling the template on another page (everything which needs to be filled is filled properly), I have a yellow triangle saying that the indicated data was not understood.

I have tested each #var separately, and each time it value is correct.

What I think is that when the #set is being evaluated, the #var are not evaluated yet, so the #set can't do the job properly.

Does anyone know a way to allow such a writing? Is it possible to force the {{ #var: Secteur }} and the {{ #var: Troncon_Temp }} to be evaluated before the #set does what it has to do in §4?

Thanks in advance for your help, and please tell me if I had not been precised enough, this is my first post here and it will be a pleasure to give you further information!

question

Most helpful comment

@Lamenax I think the issue is that you use {{#var_final: ... }} in step 3. As the documentation of #var_final states it is not possible to use it within other parser functions. This appears understandable from my point of view after reading the reason for this.

All 14 comments

I'm not really sure what you're trying to achieve, but two things do not seem right:

  • You want to print {{ #var: Point}} but there's no {{#vardefine:Point}}?
  • Again, you want to print {{ #var: Secteur }} but there's no {{#vardefine:Secteur}}?

Hello Contrafibularity,

First of all, thank you for answering so fast!

I completed my code, at first I did not write everything because I thought it would overload it. But I completed it, I hope the few explanations will help you to understand something! If still not enough, please ask! :)

The parameters the user can give are:
-Point1, Point2, Point3...
-Troncon1_Debut, Troncon2_Debut, Troncon3_Debut...
-Troncon1_Secteur, Troncon2_Secteur, Troncon3_Secteur...

The variables "Point", "Debut", "Secteur" and "Troncon_Temp" are only meant to help me see something in my code!

Wow, that's pretty convoluted stuff! Here's a thought:

If I read this correctly, printing the variable Point1 (or 2, etc.) produces a semantic annotation ( [[Point::...]]) and this value will eventually become part of a new property value (using #set),

If so, then that property (Troncon_...) should have an appropriate 'datatype', i.e. one which allows a string like [[Point::...]] to be part of the value. The default type 'Page' does not allow it because of MediaWiki's restrictions to naming pages, but 'Text' does. See for instance https://www.semantic-mediawiki.org/wiki/Help:Type_Text

Could that be what you're looking for?

Hello again,

You read that perfectly! Maybe that's convoluted, but for now it is the most efficient way I found to allow the user to define as many things as he wants (I am still learning how to use mediawiki though).

You are giving me a good advice (I mean it), but unfortunately I already specified the type of everything written on this thread...

To be really clear:

  1. At the end, Troncon_{{ #var: Secteur }} is a property, which has Text type (I made sure of it) ;
  2. Troncon_{{ #var: Secteur }} is composed of several [[Point::...]].
  3. If, for instance, I have : {{ #set: Troncon_S = [[Point::PAF1]] - [[Point::PAF2]] - [[Point::PAF3]] }}, then writing {{ #show: {{PAGENAME}} | ?Troncon_S }} will give me exactly what I expect (on my page, it is like if I only wrote [[Point::PAF1]] - [[Point::PAF2]] - [[Point::PAF3]])
  4. But here, {{ #set: Troncon_{{ #var: Secteur }} = {{ #var: Troncon_Temp }} }} raises an error, which is not the same as if SMW was trying to create a page with a wrong property content.

In my head, this is what should happen:

  • Step1: we have: {{ #set: Troncon_{{ #var: Secteur }} = {{ #var: Troncon_Temp }} }}
  • Step2: #var in Step1 are evaluated. The expression becomes then: {{ #set: Troncon_S = [[Point::PAF1]] - [[Point::PAF2]] - [[Point::PAF3]] }}
  • Step3: the Troncon_S property's content becomes [[Point::PAF1]] - [[Point::PAF2]] - [[Point::PAF3]] and everyone is happy!

Unfortunately, and according to me, Step2 is not done, SMW switch from Step1 to Step3 and does not understand what's going on.

Wow, that's pretty convoluted stuff! Here's a thought:
You are giving me a good advice (I mean it), but unfortunately I already specified the type of everything written on this thread...

You might want to try to model your example at [0] so that users involved in this discussion have a better grip on the issue at hand.

[0] http://sandbox.semantic-mediawiki.org

Hello Everyone,

You will find the template I am trying to create here :
http://sandbox.semantic-mediawiki.org/wiki/Mod%C3%A8le:PDR

And a use of it here: http://sandbox.semantic-mediawiki.org/wiki/ZZ999
Unfortunately, it seems that the Variables extension is not integrated, isn't it? I can't print on the page the value of any variable...

Unfortunately, it seems that the Variables extension is not integrated,

@kghbln ?

Ok it works I did something wrong somewhere, sorry for my mistake.

Ok guys I succeeded in reproducing the thing which turns me crazy! :D
My bad before, I forgot a somewhere and I wrote "has Type" instead of "Has type".

On the page of the template, there is a yellow triangle which looks like normal to me: it says that '-' can't be a page name. Sounds logical because {{ #var: Secteur }} can't be evaluated in the template.

But my issue is on the yellow triangle of the example. I have never seen this mistake before, and I can't figure out what it is and why it's here...

Another thing I don't understand, is that on my mediawiki, even if Troncon_S is a property with the Text datatype, Point PAF1, PAF2... will still appear to be links to their page! And that is pretty useful. I don't understand why here it is plein text.

But my issue is on the yellow triangle of the example. I have never seen this mistake before, and I can't figure out what it is and why it's here...

The error [0] is a smw_parseerror and most likely the result of [1]

{{ #set: 
 |Troncon_{{ #var: Secteur }} = {{ #var: Troncon_Temp }}
}}

due to ... following checks for Strip markers generated by MediaWiki to handle special content from parser and extension tags e.g. <pre>,<nowiki>,<math>,<source>.....

[0] http://sandbox.semantic-mediawiki.org/wiki/Sp%C3%A9cial:Browse/ZZ999-23_ERRa121c51e341a50744e32d6cd4b78c0a3

[1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/ad32c686c871d85036cf1d16a9339069b217e53f/includes/datavalues/SMW_DataValue.php#L202-L211

Hi @mwjames ,

Sorry for the delay to answer, and thank you for your answer.

So, the point is that the parser can not evaluate properly the value given to Troncon_{{ #var: Secteur }}, right? What I find strange on [0] you gave, is that {{ #var: Secteur }} is well interpreted as being 'S' in the #set function (it says that Has improper value for Troncon S, so I guess it worked at least for Troncon_{{ #var: Secteur }}). But what's at the right of the '=' sign is not interpreted! How can that be?

I can't find any solution to this issue...
The idea at the beginning was to let the user be able to define as may Points and Troncon he wanted (the number of them should not be limited or pre-defined), but now I don't have a clue of how to do that within mediawiki.

@Lamenax I think the issue is that you use {{#var_final: ... }} in step 3. As the documentation of #var_final states it is not possible to use it within other parser functions. This appears understandable from my point of view after reading the reason for this.

@kghbln : THANK YOU! :+1:
That was the issue! I never thought it could be var_final, because at step4 I tried both var and var_final, and the error was still the same! But the issue was located way before...

Thank you so much, it totally solved my problem!

Thank you @mwjames, @kghbln, @Contrafibularity, @JeroenDeDauw, that was my first request here, and I am really impressed by your reactivity and the quality of your advice.

Cool that we found the cause. Thank you for using this software.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

osnard picture osnard  Â·  3Comments

simontaurus picture simontaurus  Â·  3Comments

jaideraf picture jaideraf  Â·  3Comments

plegault3397 picture plegault3397  Â·  3Comments

alex-mashin picture alex-mashin  Â·  4Comments