output->main_content vs core_renderer::MAIN_CONTENT_TOKEN

output->main_content vs core_renderer::MAIN_CONTENT_TOKEN

by Miriam Laidlaw -
Number of replies: 2
Picture of Plugin developers

Ok, I just did that clever thing with my Moodle 2.1, 2.2, 2.3 and 2.4 installations where I got the custom themes all in one folder and all the Moodle sites looking at that one location.

Works fine.

But...

It seems that Moodle 2.1 still requires the core_renderer method for the main content? Because I get this message when I try to set one of my custom themes (which are all using the main_content method).

Fatal error: Call to undefined method theme_scratch_core_renderer::main_content() in /Applications/XAMPP/xamppfiles/htdocs/themes/scratch/layout/general.php on line 133


Line 133 in my general.php file is:

<?php echo $OUTPUT->main_content() ?>

I checked out a core theme, Afterburner, in both my Moodle 2.1 and 2.3 local sites (both updated via git today).

The Afterburner Moodle 2.1 version uses:

<?php echo core_renderer::MAIN_CONTENT_TOKEN ?>

The Afterburner Moodle 2.3 version uses:

<?php echo $OUTPUT->main_content() ?>

So this tells me that Moodle 2.1 (and presumably 2.0) still need the core_renderer method?

Is there some sort of PHP if statement I can write that says:

if moodle version is lower than X

{ ... renderer }

else ...

{ main_content }

Excuse the very poor shorthand, hopefully you get the idea?

Average of ratings: -
In reply to Miriam Laidlaw

Re: output->main_content vs core_renderer::MAIN_CONTENT_TOKEN

by Danny Wahl -

you got it there's the <2.2 version and the 2.2+ version.  And there is a simple statement you can use:

echo method_exists($OUTPUT, "main_content") ? $OUTPUT->main_content() : core_renderer::MAIN_CONTENT_TOKEN

it's basically an "if else" statement.

In reply to Danny Wahl

Re: output->main_content vs core_renderer::MAIN_CONTENT_TOKEN

by Miriam Laidlaw -
Picture of Plugin developers

Haha I just found that myself, and came back here to post that I'd found it in this thread.

<?php echo method_exists($OUTPUT, "main_content")?$OUTPUT->main_content():core_renderer::MAIN_CONTENT_TOKEN ?>

Is my friend, and I will need to use it in all my themes until such a time as I no longer need to code for any clients in 2.1. Oh, the day can not come soon enough!