General developer forum

using $OUTPUT->pix_url in language file creates an error

 
Picture of Patrick Scott
using $OUTPUT->pix_url in language file creates an error
 

I've created a "mod" named "mymod"
in /mod/mymod/lang/en/mymod.php there is this string:
<dt><img align=right alt="help" src="'.$OUTPUT->pix_url("help", "mymod").'" style="margin:5px;"/>  </dt>

which produces this error:
"The theme has already been set up for this page ready for output. Therefore, you can no longer change the theme, or anything that might affect what the current theme is, for example, the course."

I need an alternative, I need to display the image but bypass that error.
any help?


 
Average of ratings: -
Picture of AL Rachels
Re: using $OUTPUT->pix_url in language file creates an error
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi Patrick,

Whenever I run into a problem like this I try to see if I can find an example in another plugin of how it is done. In fact, I am working on the same thing for Hot Question right now. Assembling a line for output is done in the renderer.php file where I put the image and language string together. In the included picture you can see the code for creating the Remove X link and Approved toggle link, and in the second picture what the output looks like.


The last two columns is what it looks like.




 
Average of ratings: Useful (1)
Picture of Patrick Scott
Re: using $OUTPUT->pix_url in language file creates an error
 

what did you use in the language file to get the image?

 
Average of ratings: -
Picture of AL Rachels
Re: using $OUTPUT->pix_url in language file creates an error
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi Patrick,

Did not use the language file to get the image. Got the images in lines 225, 234, and 241. The actual images are in the yourmoodle/pix/t/  folder and were named delete, go, and stop. The language file is only accessed for strings for the mouse hover pop up title and the alternate text.

Each one of the variables, $remove, $approve, and $approve builds up an HTML address string that gets sent to the one line of a table, then when the whole table is built, it is sent to $output.

 
Average of ratings: Useful (1)
Picture of Patrick Scott
Re: using $OUTPUT->pix_url in language file creates an error
 

i still need to call those images from the language file somehow... still looking for a way to do so

 
Average of ratings: -
Davo
Re: using $OUTPUT->pix_url in language file creates an error
Core developersParticularly helpful MoodlersPlugin developers

The straight answer is you cannot call the images from the language file without causing the error you are seeing.

What you need to explain is not the (impossible) solution you are trying to create, but what is the actual outcome you are looking for.

If, for example, you are simply wanting to add an image within the output of a language string, then something like this would work:

$string['mystring'] = 'Blah, blah {$a->image} blah';

Then in the place where you want the text to appear:

$info = (object)['image' => $OUTPUT->pix_icon('iconname', 'alt name', 'pluginname')];
echo get_string('mystring', 'pluginname', $info);


 
Average of ratings: Useful (1)
Picture of Patrick Scott
Re: using $OUTPUT->pix_url in language file creates an error
 

I did what davo suggested.
thanks.

 
Average of ratings: -