0

I have a specific tpl being defined within the theme and the specific view function contains a function that calls the webservice.

It saves it within the items array which then outputs as variables to the tpl file. However, there is another tpl which is an alternative view for original file but currently has no values.

To fix this, in the original webservice, i store it within sessions and grab data that way. What would be the drupal solution??

function EXAMPLE_theme(){
  return array(
    'list_view' => array(
      'template' => 'list-view',
      'variables' => array('items' => NULL)
    ),
    'table_view' => array(
      'template' => 'table-view',
      'variables' => array('items' => NULL)
    )
  );
}

function list_view($form_state){
  $items = array();

  $data = form_data($form_state);

  // FOR LIST VIEW TEMPLATES
  $items['data'] = webservice($data);

  //FOR OTHER TEMPLATES (TABLE-VIEW)
  if(isset($_SESSION['data_view'])){
    unset($_SESSION['data_view']);
  }

  $_SESSION['data_view'] = $items['data'];

  return theme('list_view',  $items);
}
3
  • As side note, since your theme function is defined to use a template, list_view() will never be called. If it were, theme('list_view', $items) would cause an infinite loop, since it would be calling that theme function over and over. Also, it is good practice to prefix a theme function with theme_ and the short name of the module. And if you are overriding another theme function. hook_theme() doesn't work.
    – avpaderno
    Commented Nov 30, 2015 at 5:54
  • @kiamlaluno there is a tpl called list-view and im using variables stored within those items. That function just populates it with data
    – jagmitg
    Commented Nov 30, 2015 at 6:00
  • As I said. list_view() will never be called because Drupal loads the list-view.tlp.php file instead, as for your instructions in EXAMPLE_theme(). That is in the case no other module defines list_view as theme function: if that is the case, there is probably a conflict. And if that is the case, you cannot use hook_theme().
    – avpaderno
    Commented Nov 30, 2015 at 6:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.