-
Bug
-
Resolution: Fixed
-
Minor
-
3.11.4, 4.0
-
MOODLE_311_STABLE, MOODLE_400_STABLE
-
MOODLE_311_STABLE, MOODLE_400_STABLE
-
MDL-73332-master -
In the documentation on templates, the section on the shortentext helper states:
"The helper takes two comma separated arguments. The first is the desired length and the second is the text to be shortened. Both can be provided as context variables." (emphasis mine)
However, I was trying to provide the length argument as a context variable, and it wasn't working. After looking at lib/classes/output/mustache_shorten_text_helper.php, it was obvious that second argument, text, was looking for context variables but the first, length, was not.
// Split the text into an array of variables. |
list($length, $text) = explode(',', $args, 2); |
$length = trim($length);
|
$text = trim($text);
|
|
// Allow mustache tags in the text. |
$text = $helper->render($text);
|
|
return shorten_text($text, $length) |
Again, emphasis mine.
After some testing, adding
$length = $helper->render($length);
|
does, indeed, seems to fix the problem and align the code with the documentation.
Obviously this isn't a well-exercised issue - or it would have been found by now, so I'm including a patch for the current main branch.