pull a GlobalArea & Block using Ajax
Permalink
Hello everyone
I am trying to pull a GlobalArea using Ajax with NO success at all.
This is what I have done:
[Theme Controller]
// path: /packages/theme_lazy4site/controller.php
I've created a Route there:
[My Ajax Call]
This is my JQueryAjax Call
[AjaxTools Class]
This is my AjaxTools Class and Method
I am trying to display the global area within that particular Block (Type Handler called lazy_contacts) view.
[Questions]
My question is why if I try to display the actual global area "$global->display();" I get NO result at all?
where if I loop the global area and I display the only block inside "${$b_name}[0]->display();" I get the result?
[One more thing]
I get this error message and I wouldn't know how to solve ..
Also .. I have more work of this kind and I would appreciate if someone would be available to help me and to get paid well of course.
The work would be about pulling 1 or 2 more Blocks by Ajax.
Kind Regards
Matteo Montanari
I am trying to pull a GlobalArea using Ajax with NO success at all.
This is what I have done:
[Theme Controller]
// path: /packages/theme_lazy4site/controller.php
I've created a Route there:
Route::register('/ajax/getContacts', '\Concrete\Package\ThemeLazy4site\Block\LazyContacts\Ajax\AjaxTools::getBlock');
[My Ajax Call]
This is my JQueryAjax Call
jQuery.ajax({ url: '/ajax/getContacts', dataType: 'html', type: 'post', cache: false, data: { cID: CCM_CID, // this is the Page ID }, success: function(response) { $this.html(response); } });
[AjaxTools Class]
This is my AjaxTools Class and Method
I am trying to display the global area within that particular Block (Type Handler called lazy_contacts) view.
class AjaxTools extends Controller { public function getBlock() { $c = Page::getByID($this->getCID()); // - - - - - - - - - - - - - - - - - - - - - - - - // Section: Contacts // $b_name = 'Contacts Form'; $b_type = 'lazy_contacts'; $global = new GlobalArea($b_name); $global->disableControls(); if($global){$$b_name = $global->getAreaBlocksArray($c);} if(is_array(${$b_name})) { try { if(is_object(${$b_name}[0]))
Viewing 15 lines of 27 lines. View entire code block.
[Questions]
My question is why if I try to display the actual global area "$global->display();" I get NO result at all?
where if I loop the global area and I display the only block inside "${$b_name}[0]->display();" I get the result?
[One more thing]
I get this error message and I wouldn't know how to solve ..
Call to a member function getAreaCustomStyle() on a non-object in /concrete/elements/block_area_header_view.php
Also .. I have more work of this kind and I would appreciate if someone would be available to help me and to get paid well of course.
The work would be about pulling 1 or 2 more Blocks by Ajax.
Kind Regards
Matteo Montanari
Hello Jero
Thanks for the message, helpful.
What you are saying makes sense and that actually is an approach I remember I read about some days ago.
It was a well written article even though based on an older version of concrete5, it has been useful and a pleasure to read.
Here it is: http://tinyurl.com/qaaxp7n
There's also a video .. which is quite straight forward and nice to watch
Thanks for the message, helpful.
What you are saying makes sense and that actually is an approach I remember I read about some days ago.
It was a well written article even though based on an older version of concrete5, it has been useful and a pleasure to read.
Here it is: http://tinyurl.com/qaaxp7n
There's also a video .. which is quite straight forward and nice to watch
tried to achieve it with the page type controller instead?
I wouldn't be able to locate a page type controller actually.
Could you please give some more information about this approach.
Could you please give some more information about this approach.
do you want to have the block infos just to be displayed or do you also want to have forms or other inputs to be functional?
I would like just the block infos and content to be displayed.
That would certainly be enough.
That would certainly be enough.
A possible solution might be to have a special page template or event better a single page that does not have a header or footer etc, but instead has a bit of logic to decide which global area is requested and then declares that area, displays it and dies. If you call that page using ajax, It should just display the block and exit. Using a page like this also avoids having to add routes.