Fuel bar inline edit buttons and controllers with CMS content
I've been creating controllers and views (eg home page, news events etc) that pull in CMS content if the CMS page of the same name exists - so if "news" exists at "/news" and there is a controller of the same name, I fetch CMS and add it to the variables that make the view. That way I get say, a news module listing, and optionally, CMS content above it.
In v1.0 I use $this->fuel->pagevars->retrieve($this->uri->uri_string()) to get the CMS content (in MY_Controller), merge any controller content in with the CMS layout array, and use $this->fuel->pages->render($view, $all_vars) where $all_vars is the merge of layout variables and custom content.
When rendered in the view, and you are logged in as admin, the Fuel bar inline editor menu appears, but the edit links are not displayed, neither are the pencil icons against the content (eg page_title, body), although the view uses fuel_var() to fetch "page_title" and "body".
What could I do to make the inline editing function? The fuel_var() methods place the __fuel_marker__ spans in the right place, so I suppose some JQuery trigger is not firing.
Comments
I'll spell out what I'm doing a bit more. In MY_Controller I have a method renderCMS():
/* * Merges controller vars with CMS vars and renders page */ function renderCMS($view, $controller_vars = array()) { // default to home page content (if any) $page_vars = ($this->uri->uri_string() != '') ? $this->fuel->pagevars->retrieve($this->uri->uri_string()) : $this->fuel->pagevars->retrieve('home'); $all_vars = array_merge($page_vars, $controller_vars); $this->fuel->pages->render($view, $all_vars); }
and then in a controller (extended from MY_Controller) I will use:
$vars = array(); $vars['some_custom_content'] = $this->some_model->some_method(); $this->renderCMS('home/index', $vars);
so the render() method will then fetch and merge CMS content with any custom controller stuff. This all works nicely, but when fuel_var() is used to echo out "body", the span elements (__fuel_marker__) appear in the right place, but the fuel bar isn't responding to the content available. I'm trying to work out what triggers the pencil and other edit functions. Then I'd be really happy!
Something is present for the CMS controller that isn't for MY_Controller?
$this->fuel->pages->render($view, $all_vars, array('render_mode' => 'cms'));
Incidentally the User Guide doesn't list the value "cms".
Thank you, that's actually a big step forward for my use of FUEL v1.
In the code examples above, I'm loading a view that has the home page layout eg (in a simplified way):
<?php // Kill default layout by setting the value to empty fuel_set_var('layout', ''); $this->load->view('_blocks/header'); ?> <h1><?php echo fuel_var('page_title'); ?></h1> <?php echo fuel_var('body'); ?> <?php $this->load->view('_blocks/footer'); ?>
However, with render_mode => 'cms' the content loaded in _blocks is removed completely. Is that correct?. I suppose that's what 'cms' means - just render the db contents at this url !?
To get round this I now have a layout file that in effect does the job of the view. So for the page 'home' in the CMS I can set layout as 'home' (ie from the views/_layouts folder), and now the HTML for the home page is rendered along with the CMS, AND any content from the controller 'home' - provided the layout array is specified in MY_fuel_layouts!
I tend to make most custom controllers allow CMS content to be added, so now I'm looking at a different way of working, where custom 'views' now become custom 'layouts' in the _layouts folder, and for each there is an entry in MY_fuel_layouts to allow the admin CMS to show fields for that layout file. It's the price to pay though to allow inline editing to work properly.
I suppose the controller $this->fuel->pages->render() method should now not load the view file ('home/index'), but instead specify the url location 'home'? In fact, if the 1st argument contains a '/' it must imply a file path, and therefore a view.
I've noticed this as controller+cms pages don't seem to respect published status, unless honor_page_status is true.
For the publish status, I've just pushed change to add "vars_honor_page_status" like so:
$this->fuel->pages->render($view, $all_vars, array('render_mode' => 'cms', 'vars_honor_page_status' => TRUE));
The Fuel bar will recognise the page is not published, but the CMS content is still visible when you are not logged in.
What I've done now is use
$this->fuel->pages->find(uri_string());
to test for the published status, as find() honours the status, so if the return from that is empty, I know I should 404 instead.
So to summarise, inline editing is only possible with with mixed source content (ie CMS + controller content and or variables content) IF a separate layout file is used.
I can live with that! Thanks again! Is version 1 for release soon?
I've tried to express all this in my blog: http://adventuresincms.blogspot.co.uk/2013/02/the-ins-and-outs-of-inline-editing-in.html
With regards to version 1, we are hoping to release it soon but I've been saying that for a while. Internally, Daylight uses it exclusively for all new projects. However, we have a few things related to FUEL we want to do first.