1

I create a view (FO) that lists certain content type. By default, I put a pager (mini) and a number of items per page (content 10 per page).

This view, I integrated into a content type (CFTO) in addition to other parameters. If I agree, I want to use my other variables to redefine this view without saving it in a database (eg disable the pager / display 3 content page / ...)

I try different hooks as hook_views_pre_view, hook_views_pre_render, views_pre_build, but nothing works. I can not change the number of a content page. This is my different test :

I wish i could change my view different information as enable / disable pager and more then change the number of elements of the page.

I find a way of hook_views_pre_render(&$views) to change the pager and more. It works well.

function my_views_pre_render(&$view){
//For more
$view->display['page']->handler->options['use_more'] = TRUE;

//For pager
if(!$this_node_pager_value) {
    $view->query->pager->set_items_per_page($view->total_rows);
    $view->query->pager->update_page_info();
}}

Now i wish i could change the number of elements in my page to display, I tested this code in different hook sities previously.

function my_views_pre_render(&$view){
if($this_node_pager_value) {
//TEST 1
$view->query->pager->set_items_per_page(3);
$view->query->pager->update_page_info();

//TEST 2
$view->exposed_raw_input['items_per_page'] = 3;
}}

function my_views_pre_view(&$view, &$display_id, &$args){
//TEST 1
$view->display_handler->display->display_options['pager']['options']['items_per_page'] = 3;

//TEST 2
$view->query->pager->set_items_per_page(3);
$view->query->pager->update_page_info();

//TEST 3
$view->exposed_raw_input['items_per_page'] = 3; 
}

function my_views_pre_execute(&$view){
//TEST 1
$view->display_handler->display->display_options['pager']['options']['items_per_page'] = 3;
//TEST 2
$view->query->pager->set_items_per_page(3);
$view->query->pager->update_page_info();
//TEST 3
$view->exposed_raw_input['items_per_page'] = 3;
//TEST 4
$view->display_handler->set_option('items_per_page', 3);
}


function cci_generic_views_pre_build(&$view){
//TEST 1
$view->pager["items_per_page"] = 3;
//TEST 2
$view->display_handler->options['pager']['options']['items_per_page'] = 2;
//TEST 3
$view->display_handler->options['pager']['options']['expose']['items_per_page'] = 2;
}

None works. Would you know what should be done to make it work?

You would know what is the right hook to use? And how to change this value? thank you for your help

Djik

  • Hey, welcome! Please provide code samples of what you have tried and also include specific descriptions of what it is that didn't work. Just saying "nothing works" is not very helpful. – berliner Feb 4 '14 at 16:29
  • I wish i could change my view different information as enable / disable pager and more then change the number of elements of the page. I find a way of hook_views_pre_render(&$views) to change the pager and more. It works well. $view->display['page']->handler->options['use_more'] = 1; Now i wish i could change the number of elements in my page to display, I tested this code in different hook sities previously. code None works. Would you know what should be done to make it work? – Djik Feb 5 '14 at 14:08
  • 1
    Please edit your question and more details there. If you write additions here in the comments it is difficult to get a fast overview of your situation. And please include some code. – berliner Feb 5 '14 at 14:10
  • I rest the simplest issue in this address [drupal.stackexchange.com/questions/102639/… Can you help me? – Djik Feb 10 '14 at 9:32
0

The following should work in hook_views_pre_build(&$view):

$view->set_items_per_page(5);
  • Great, it works. Thank you! By chance, is that you know the method to disable the pager? again thank you – Djik Feb 10 '14 at 13:02
  • Please post questions for specific issues. This site is not intended to be a discussion list. And don't forget to accept the answer if it solves your problem ;) – berliner Feb 10 '14 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.