I recalled that $this->data = $this->fuel->pagevars->retrieve(uri_segment(1));is one way of getting ANY vars, but the main layout doesn't get applied. Looking back at other advanced module layouts, I have repeated the main layout inside of the module, but this seems un-DRY
$vars = array(); // ... add any other $vars to your page outside of the CMS
$this->fuel->pages->render('my_uri', $vars, array('view_module' => SHOP_FOLDER));
would render the 'category' view inside the 'shop_main' layout from the SHOP_FOLDER module when used from a shop module controller. But in fact the /application/ 'main' layout is used (which isn't named 'shop_main' so I guess that key is ignored). So the 'view_module' key doesn't set the layout to be from the same folder (understandable) but is there a property that would make use of a module layout file?
I realise I'm now asking the opposite of how the thread began!! I'm fine keeping the layout in the application folder, which is what I wanted, but I'm curious!
My folder structure in the module is vanilla HMVC:
I believe the reason why that layout key isn't working is probably because it's not defined as a layout in MY_fuel_layouts.php. In that case, there is a "module" property you can specify in your layout definition as SHOP_FOLDER.
Comments
What's the code you are using to create the page?
Well for example:
$this->load->module_view(SHOP_FOLDER, 'category', $this->data);
I recalled that
$this->data = $this->fuel->pagevars->retrieve(uri_segment(1));
is one way of getting ANY vars, but the main layout doesn't get applied. Looking back at other advanced module layouts, I have repeated the main layout inside of the module, but this seems un-DRYSo looking back at previous advanced modules I've done, and I think sort of like the blog module, I've ended up doing this sort of thing:
This is necessary because of the HMVC structure?
Correct. You could also try the following:
yes - that's much neater, plus handles the layout in the 3rd arg
array('view_module' => SHOP_FOLDER, 'layout' => 'shop_main')
Many thanks!
I anticipated that
$this->fuel->pages->render('category', $this->data, array('view_module' => SHOP_FOLDER, 'layout' => 'shop_main'));
would render the 'category' view inside the 'shop_main' layout from the SHOP_FOLDER module when used from a shop module controller. But in fact the /application/ 'main' layout is used (which isn't named 'shop_main' so I guess that key is ignored). So the 'view_module' key doesn't set the layout to be from the same folder (understandable) but is there a property that would make use of a module layout file?
I realise I'm now asking the opposite of how the thread began!! I'm fine keeping the layout in the application folder, which is what I wanted, but I'm curious!
My folder structure in the module is vanilla HMVC:
application
-views
category.php
--_layouts
---shop_main.php
I believe the reason why that layout key isn't working is probably because it's not defined as a layout in MY_fuel_layouts.php. In that case, there is a "module" property you can specify in your layout definition as SHOP_FOLDER.
OK, so this is a bit late, but I found a solution!
In MY_fuel_layouts.php as you suggested:
/**
* For shop module
*/
$config['layouts']['shop_main'] = array(
'module' => SHOP_FOLDER
);
then in the controller:
....
$this->data['layout'] = $this->page_props['layout'];
$this->fuel->pages->render('categories', $this->data, $this->page_props);