[LON-CAPA-users] style file and extracting parameters
Raeburn, Stuart
raeburn at msu.edu
Fri Mar 15 13:19:01 EDT 2019
Hello HK,
1. Answer to Q1: "How is the javascript link formulated?"
The javascript link for previous tries will be: "LONCAPA_previous_tries_" with the following appended: $prefix.$Apache::lonxml::curdepth.'_'.$env{'form.counter'}
where
(a) $prefix is empty, unless displaying a student's view of a problem in the grading interface.
(b) the value of $Apache::lonxml::curdepth is a string of digits separated by underscores, which encapsulate the nesting level for the closing part tag (or problem tag for a problem without parts), and also a count of how many tags there were previously at the same level.
(c) $env{'form.counter'} is an integer which will be the same for all the different parts in a problem, but will be different if the web page is reloaded.
For example, for a rendered problem in which a style file is use, with a definition for the problem tag, a value of $Apache::lonxml::curdepth might be:
1_1_4_6_1
(i.e., 1 for the outer problem tag, 1 for the problem tag inside the render tag (for definetag name="problem") in the style file, 4 for the number of top level tags inside the problem tag in the style file, 6 for the number of next level tags etc.).
*****
2. Answer to Q2, "how can the id, etc for the <part> be extracted",
If you mean the id attribute of the part tag, then that can be accessed using $external::part in a script block that is included *after* the <part> tag in the <definetag name="part"> section.
*****
3. Additional information:
Consider the following style file:
<definetag name="problem">
<render>
<problem>
<script type="loncapa/perl">
$numparts = scalar(split(/,/,&EXT('resource.visibleparts'));
</script>
</render>
</definetag>
<definetag name="part">
<render>
<part>
<script type="loncapa/perl">
$label = 'Part '.$external::part;
</script>
<block condition="$numparts > 1">
<web>
<div class="someclass">
$label
</web>
</block>
<block condition="$numparts == 1">
<web>
<div class="lsomecotherclass">
</web>
</block>
</render>
</definetag>
<definetag name="/part">
<render>
<web>
</div>
</web>
</part>
</render>
</definetag>
When using <block></block> tags like this within a <definetag name="part"> item in a style file to wrap <div> tag(s) which are not closed until a later <definetag name="/part">, you will run into problems because the apparent failure to close the <div> will be detected, and a warning such as: "Found tag /block on line 1 when looking for /div in file" will be displayed.
In addition, both the div and block tags will be removed from the end of the tag array, by calls to Apache::lonxml::decrease(). This causes further parsing problems later when the /div tag itself is encountered in the <definetag name="/part"> section, because that results in the following warnings:
Found tag /div on line 1 when looking for /part in file.
Found tag /div on line 1 when looking for /part in file.
Found tag /part on line 1 when looking for /problem in file.
Found tag /part on line 1 when looking for /problemin file.
because the tag array is progressively reduced from: ('problem,'problem','div','part','part') to ().
The value of Apache::lonxml::curdepth then becomes _ and the function name in the javascript link would then be: LONCAPA_previous_tries__$env{'form.counter'}, will no longer be unique for each part displayed.
As a workaround you can modify the style file in one of two ways.
Either (a) move the </part> tag so it occurs before the /div in the <definetag name="/part"> section, or (b) move the <part> tag so it occurs after the <block></block> tags within the <definetag name="part"> section.
Note: if you use (b) then the label will display the id of the previous part. i.e., $external::part will not yet be set to the current part (because rendering of the <part> tag has not yet occurred), so you'd need to find another way of labeling parts.
A change to the LON-CAPA code that would circumvent this problem without either workaround would be to replace this line:
my $function_name = "LONCAPA_previous_tries_".$prefix.
$Apache::lonxml::curdepth.'_'.$env{'form.counter'};
with:
my $function_name = "LONCAPA_previous_tries_".$prefix.
$Apache::lonxml::curdepth.'_'.$Apache::lonxml::counter;
Stuart Raeburn
LON-CAPA Academic Consortium
________________________________________
From: LON-CAPA-users <lon-capa-users-bounces at mail.lon-capa.org> on behalf of H. K. Ng <hkng at fsu.edu>
Sent: Thursday, March 14, 2019 9:33 AM
To: Discussion list for LON-CAPA users
Subject: [LON-CAPA-users] style file and extracting parameters
Good morning,
I have a sty file that is used to display problems in the same format. However, I just run into a issue that I haven't seen before. When I click on "Previous tries" link for a multi-part problem, it doesn't display the correct previous attempts for one or more parts. It displays the previous tries for one of the other part that works. Looking at source code, the javascript script link for the previous tries for the offending part is the same as the link the shows the correct tries.
Q1: How is the javascript link formulated?
Q2: Is there a way to extract the parameters for a tag, for example,
<definetag name="part">
how can the id, etc for the <part> be extracted? My suspicion is that the id is somehow "corrupted" by the style file.
Thanks,
-hk
More information about the LON-CAPA-users
mailing list