Changing set_pagelayout from Theme

Re: Changing set_pagelayout from Theme

by Mary Evans -
Number of replies: 10
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

If you want to change something in a theme that refers to the layout of an Admin page then you can set this as a specific layout in your theme's config.php as the Admin part of the THEME->layouts = array ();

Which would look like this:

THEME->layouts = array (

    // Server administration scripts.
    'admin' => array(
        'file' => 'fullpage.php',
        'regions' => array(),
    ),

)

Then you would need to create a fullpage.php file that has the layout you require for your site's Administration pages which are called from Moodle CORE using:

$PAGE->set_pagelayout('admin');

This is assuming that this is the goal you want to achieve?

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Changing set_pagelayout from Theme

by Syed HameedUllah -

Thank you so much Mary,

I have created the fullpage.php in the layouts but that will change the layout for all the pages with 'admin' as their page layout.

I just want to change the view of a single page instead of changing the layout file.

I mean to say that I don't want to change the admin layout of all the page having it.

changing the layout name of a particular page:

$PAGE->set_pagelayout('admin');
to 

$PAGE->set_pagelayout('something');
only via theme.

Thanks

Hameed

In reply to Syed HameedUllah

Re: Changing set_pagelayout from Theme

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Hameed,

You're stating what you think is the solution, but I don't think it is.  However you've not described what you're really trying to do and why with specific pages.  Therefore please provide more information.

Kind regards,

Gareth

In reply to Gareth J Barnard

Re: Changing set_pagelayout from Theme

by Syed HameedUllah -
Hi Gareth,

In shortest way I want to know if we can change the layout name defined in /message/index.php

$PAGE->set_pagelayout('standard');
only Via theme.


Reason/Example:
Page 1: The messages page(/message/index.php) has the layout set as "standard".

Page 2: The calender view(/calendar/view.php?view=month) also has "standard layout".

Now I need to add some regions(suppose side-post) only to the messages page for which I have 

duplicated the columns2.php file in as /theme/mytheme/layout/standard.php.


In mytheme/config.php,

The standard layout is defined as

// Standard layout with blocks, this is recommended for most pages with general information.
'standard' => array(
	'file' => 'standard.php',
	'regions' => array('side-pre', 'side-post'),
	'defaultregion' => 'side-pre',
)


If I do so the region side-post will be on the Page2 also. Is there any way I can use two different layout files for single layout.

Hope I cleared myself...

Thanks n Nice day...

In reply to Syed HameedUllah

Re: Changing set_pagelayout from Theme

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

In your standard.php file when $PAGE->pagetype is 'message-index' then adapt the layout as you need.  Then for the calendar, look at the body tag id and remove the 'page-' prefix to work out what the string is - ditto.

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Changing set_pagelayout from Theme

by Syed HameedUllah -

Thank you Barnard

In reply to Syed HameedUllah

Re: Changing set_pagelayout from Theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

I have just had an idea and will test it out as it may be a simplery solution for what you are trying to achive.

But don't hold your breath! LOL

Mary

In reply to Mary Evans

Re: Changing set_pagelayout from Theme

by Syed HameedUllah -

cool

Thanks mary.

I tried doing this,

$this->page->set_pagelayout("fullpage");
but was of no use...
In reply to Syed HameedUllah

Re: Changing set_pagelayout from Theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I ran out of time...I think it is possible to define when the layout needs to change by getting $this->pagetype == 'message-index'; using a renderer and then adding a restyle of page in layout/columns2.php (copy) by just adjusing the region-main and making side-pre into side-post.

But then again there are other ways probably...but like Gareth I'm short of time as it can be so very frustraiting trying to figure out how Moodle actually works.

It's so complex these days.

I was thinking something like this in the layout file.
(based on theme/clean/columns2.php)

// Get the HTML for the settings bits.
$html = theme_clean_get_html_for_settings($OUTPUT, $PAGE);
global $CFG;
require_once($CFG->dirroot . '/lib/pagelib.php');

if ($this->page->pagelayout == 'standard' && $this->pagetype == 'message-index') {
    $regionmain = 'span9 desktop-first-column';
    $sidepre = 'span3 pull-right';
} else {
    $regionmain = 'span9 pull-right';
    $sidepre = 'span3 desktop-first-column';
}

Cheers

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Changing set_pagelayout from Theme

by Syed HameedUllah -

Thanks Mary...

In reply to Syed HameedUllah

Re: Changing set_pagelayout from Theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I think I have it! At least it worked in the page I wanted it to.

Since I do not know what theme you are using as this will also need some adjusting.

But using Moodle 3.3 Clean theme with this small change to the columns2.php layout

this will change the position of a side-pre (left) to display on the (right)

Changes are needed in the following places:

  1. theme/clean/layout/columns2.php (make copy and rename to standard.php)
  2. theme/clean/config.php
Please add the following conditional code to the standard.php just
below the section as seen here below!
1.)
// Get the HTML for the settings bits.
$html = theme_clean_get_html_for_settings($OUTPUT, $PAGE);

global $CFG, $SITE;
if ($this->page->pagetype == 'message-index') {
    // Special case for message page - please do not remove.
    $regionmain = 'span9 desktop-first-column';
    $sidepre = 'span3 pull-right';
} else {
    $regionmain = 'span9 pull-right';
    $sidepre = 'span3 desktop-first-column';
}
Please add to the theme/clean/config.php
2.)

$THEME->layouts = array(
    // Standard layout customised layout.
    'standard' => array(
        'file' => 'standard.php',
        'regions' => array('side-pre'),
        'defaultregion' => 'side-pre',
    ),
);

Hope this helps?

Mary

Average of ratings: Useful (1)