Answer the question
In order to leave comments, you need to log in
Content rendering algorithm using ajax and cookies in drupal 7?
Hello. The situation is this, it is necessary to organize the output of content, depending on the value of the cookie. Those. there are two options for displaying the node, (line and block), the output changes depending on the value of the cookie, i.e. I stupidly use a check for cookies in node.tpl.php (though in hook_node_view - that's not the point). All this business certainly works, ie. by clicking on the buttons I change the value of the cookie, then the page reloads and we get the output format we need.
Now what's the difficulty? The whole thing refuses to work correctly when using ajax. Those. according to PHP rules - the assigned cookies are available on the next page load. Now my algorithm is
<?php
/**
* Implements hook_menu()
*/
function module_menu() {
$items['domptabview'] = array(
'page callback' => 'ajax_link_response',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Отдаем полученный результат браузеру
*/
function ajax_link_response($type = 'ajax', $nid = 0) {
$output = _module_load_noder($nid);
if($type == 'ajax'){
$commands = array();
$commands[] = ajax_command_replace('#block-system-main .view-content', '<div class="view-content">' .$output .'</div>');
$page = array(
'#type' => 'ajax',
'#commands' => $commands
);
ajax_deliver($page);
}else{
$output = '<div class="view-content">' . $output . '</div>';
return $output;
}
}
/**
* Получаем содержимое ноды и возвращаем HTML
*/
function _module_load_noder($nid = 0) {
// загрузили ноду
$node = node_load($nid, NULL, false);
if ($node) {
$vnode = node_view($node, 'teaser');
return drupal_render($vnode);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question