0

I created a library content type. Its view is library__view; this view has a page display whose path is library, which has a contextual filter on the subject of the books(e.g. math, physics).

I created a page in my theme folder, and renamed it page--library.tpl.php. I also embedded library__view using this line.

views_embed_view('library__view','page');

The problem is that library/math does not show math books (while it works right in the view administrative menu).

What is wrong with this? What is the filename of a view whose path is specified to be in a certain URL (e.g. page--library.tpl.php, library.tpl.php)?

11
  • "library/math does not show math books" so what it shows? Error message? Empty result set? And is it empty when you're logged in as admin? Is it a matter of filter? View without filter works OK?
    – Mołot
    Oct 3, 2013 at 13:18
  • have tried with some other path ?
    – Bala
    Oct 3, 2013 at 13:20
  • 2
    Is there any reason why you are embedding a view in a custom page tpl instead of just creating a page view and assigning it the path of library? You shouldn't need a custom tpl file at all for this.
    – rooby
    Oct 3, 2013 at 14:17
  • @rooby this is exactly my problem, I don't know how to create a page view
    – M a m a D
    Oct 3, 2013 at 22:08
  • @Mołot it shows page--library.tpl.php page
    – M a m a D
    Oct 3, 2013 at 22:09

1 Answer 1

1

I infer: you have created the view for listing the contents of library content type, now you are embedding that view in the page template file for theming the contents listed on the page created by view. If this is the case than you are doing the things in incorrect way.

Possible cases for creating the template file for views page:
1. Theme the contents rendered by views on http://www.yourdomain.com/library page: For this you need to create template file as per the views template suggestion, also its best to create the template for view from the suggestion generated by view at Theme: Information as below:

enter image description here The suggestions for creating the template in the below image is based upon the "test-contact" page I have created in views: enter image description here

2. Theming the content created for library content type: If you want to theme the contents that is rendered while creating a nodes of library type than you need to create the node--library.tpl.php. This template will be just for theming the contents of library content type created originally (not for the content listed on library page created from views) and it wont have any impact on your views page.

Now coming to your issue of page at `library/math' does not show math books:

  • Check if the result in your created view displayed correctly (to confirm that the contextual filter is working fine) on passing math as argument to "Preview with contextual filters" (present at bottom of view).
  • Make sure that the path of page that you are creating from view is /library, and for testing purpose you can try changing the path temporarily to /library123 (If changing the path, than test the result at yourdomain.com/library123/math page)
  • Remove the template you have created for embedding the view (as it doesn't seems to be needed, at least as of now)
  • Clear the cache and check again (not needed logically but no problem for testing purpose)
9
  • I created views-view--library__view--page.tpl and I found that the embedded view inside page--library was rendered through this .ok it is good but here is a problem; page--library is just a page and can have multiple views that are embedded inside it,right?so if I add /math after its url how does drupal understand that /math belongs to library__view?so I deleted page--library and expected that I could see output of views-view--library__view--page.tpl when I visit /library page, but I just saw my page.tpl.php .I guess library__view must be somehow embedded some where
    – M a m a D
    Oct 4, 2013 at 9:55
  • @Mohammad Have you cleared the cache of site, and one more thing I am not getting is why are you trying to embed the view in template file. Also drupal will automatically take care of the arguments you pass on /library page, can you once try and check Oct 4, 2013 at 10:05
  • Yes I have, because I don't know how to output views on their path (what file I must create to display views on their specified path? what is its name?) , the only way I know is to embed them! like I said I created **views-view--library__view--page.tpl ** page and wrote <?php print 'hello'?> inside of it, but when I visited /library page I saw my page.tpl.php ! it means views-view--library__view--page.tpl was not rendered.
    – M a m a D
    Oct 4, 2013 at 10:09
  • @Mohammad Ok, That I was guessing and I have mentioned in my answer also. So If you want to output the view on their path i.e library than no need to create any template file for it, drupal will automatically render the view at library page once you created it from views UI. So now remove any custom template file you have created for checking the output of view and than check the result of library page (after clearing the cache). Let me know if problem doesnt get resolved Oct 4, 2013 at 10:13
  • I tried this and it didn't display library content; but fortunately I found a solution for contextual filter problem and i sent arguments to views_embed_view() and drupal treated these arguments as contextual filter, so the problem solved. but it is still wondering me why /path does not work!
    – M a m a D
    Oct 4, 2013 at 10:43

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.