-1

I have a custom page that show a list of item generated by a view.

These items should link to each item page that is a custom page as well created by another view and that use contextual filter (id from url) to show it.

How can I link from the list to the specific view? The system says page not found (404). I use this:

var link = l('' + row.title, 'pathview/' + row.nid);

pathview/ is the path assigned in the view (if i write it in the browser it works)

The browser console show this in the link (72 is an example):

<a href="#" onclick="javascript:drupalgap_goto('pathview/72');" class="ui-btn ui-btn-icon-right ui-icon-carat-r">Item Title</a>

Thanks in advance, Cris.

2 Answers 2

1

This docs page has a perfect example for what you need here: http://docs.drupalgap.org/7/Views/Displaying_a_View/Views_Render_Array

The only difference is, first you need to create a page in your app that takes in a page argument (http://docs.drupalgap.org/7/Pages/Page_Arguments).

Then when it comes time to render that page, add a View widget/render-array to your page. You'll configure that View widget to pull from 'pathview/' + nid

2
  • Unfortunatelly it is not very clear to me how to do the page argument, everything is fine if is a node but when I try to load the views content and I create the page is not showing. Any help will be appreciated, thanks
    – Crispy
    Commented Aug 7, 2017 at 19:53
  • 1
    Please update your question to include the code you are using to build these two pages, and I'd be happy to take a look, thanks. Commented Aug 7, 2017 at 20:49
0

Ok, I've done some research and after a lot of try, these are my 2 pages:

Custom module for the page with the list of items out of a drupal views

function mymodule_list_menu() {
  var items = {};
  items['articles'] = {
    title: 'Friend\'s list',
    page_callback: 'mymodule_list_articles_page'
  };
  return items;
}

/**
 * The page callback to display the view.
 */
function mymodule_list_articles_page() {
  try {
    var content = {};
    content['my_articles_list'] = {
      theme: 'view',
      format: 'ul',
      path: 'my-articles', /* the path to the view in Drupal */
      row_callback: 'mymodule_list_articles_list_row',
      empty_callback: 'mymodule_list_articles_list_empty',
      attributes: {
        id: 'my_articles_list_view'
      }
    };
    return content;
  }
  catch (error) { console.log('mymodule_list_articles_page - ' + error); }
}

/**
 * The row callback to render a single row.
 */
 function mymodule_list_articles_list_row(view, row, variables) {
  try {
      if (row.immagine.indexOf('http') > -1){
          img = {
              my_custom_image:{
                theme:'image',
                path:row.immagine,
                alt:'gift',
                title:'gift'
              }
            };
            img1 = row.immagine; 
        }else{
          var image_html = theme('image', { path: row.immagine.src });
          img = image_html; 
            img1 = "---"; 
        }
      var title_html = row.nome+" "+row.cognome.charAt(0)+"."+" "+row.title;
       var image_html = theme('image', { path: row.img.src });

      var link = l('' + title_html + image_html, 'singlegiftapp/' + row.nid);
      return link;

   }
  catch (error) { console.log('mymodule_list_articles_list_row - ' + error); }
}

function mymodule_list_articles_list_empty(view, variables) {

  return t('Sorry, no articles were found.');


}

Custom module for the page with the single item after clicking one in the previuos list and that call another drupal views

  function mymodule_single_menu() {
  var items = {};
  items['singlegiftapp/%'] = {

    page_callback: 'mymodule_single_page',
    pageshow: 'mymodule_single_pageshow',
    page_arguments: [1]
  };
  return items;
}


function mymodule_single_callback(callback, nid) {
  node_load(nid, {
    success: function(node) {
      callback.call(null, node.title);
    }
  });
}

function mymodule_single_container_id(nid) {
  return 'gift-' + nid;
}

function mymodule_single_page(nid) {
 var content = {};
  content['divname'] = {
    theme: 'jqm_item_list',
    title: '',
    items: [],
    attributes: { id: 'divname' }
  };
  return content;
 }

function mymodule_single_pageshow(nid) {
  var path_to_view = 'singlegiftapp/'+nid;
  views_datasource_get_view_result(path_to_view, {
    'success':function(data){

    if (data.nodes.length > 0) {
        var items = [];

        $.each(data.nodes, function(index, object){
              var row = object.node;


             var image_html = theme('image', { path: row.img.src });

               var description =
                '<h1>' + row.title + '</h1>' +
                '<p> ' + row.field_anothertext+ '</p>';
               var dato = t(description+image_html);
              items.push(dato);

        });
         drupalgap_item_list_populate("#divname", items);
      }
    }




  });

}

These 2 module are working for me based on my views. Hope that would help to someone...

Your Answer

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

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