I want to create a custom page.tpl.php file for a specific view. I have a view but I want it to look different from a standard page and I have other content I want to display on the same page as the view that I want to be able to style with an external stylesheet. However I'm not sure what the node id of the page created by the view is, so I can't reference it in a page-node-x.tpl.php file. How can I find the node ID or is there a better way to achieve this goal? Perhaps a way to embed a view within a page.

I am using Drupal 6 and Views 2.

I'm not sure if I've described my problem very well, so if there are any questions just ask.

Cheers.

Comments

nevets’s picture

Some pointers

1) Only nodes have node id's and views are not nodes.

2) If you want to add other content to the same page, it sounds like you may want to investigate the panels module. You can use panels to create page layouts and add content as needed.

awm6392’s picture

Ok so as stated above, a view isn't a page and so doesn't have a page template file. So what is the naming convention for custom views template files? I located all the view template files in my views folder. Obviously I don't want to just go around messing with the originals, as I only want a particular view to be affected. How can I do this?

d3zign7reak’s picture

awm6392, were you able to figure this out? Im running into the same issue.

awm6392’s picture

I found a workaround where i could edit the output of the view within the views interface itself. it seems to get the job done so i stuck with that. its a lot more simple than trying to have a whole new template for a view.

benced’s picture

you can make templates based on a URL

for example the url for a page generated by a view I've made is www.example.com/slideshow (where www.example.com is the base URL for the website)

The page template for this page is thus page-slideshow.tpl.php

This template will also effects pages i've made called www.example.com/slideshow/2 and any of the other "sub-directories" of the slideshow "directory"

if you want a different page template for a specific "sub-directory" (that will overide the directory template you made on the subdirectory page) just continue the pattern

example for www.example.com/label1/label2/label3/label4

the page template is page-label1-label2-label3-label4.tpl.php

You also may want to look at the "Theme Information" option in the "Page" tab on the edit page for your view which shows you the template names that can be used to effect each section of the view itself (if you havn't already)

caponey’s picture

benced,
if i create a view with a page to example.com/myview
then create a page-myview.tpl.php, that page is blank, which makes sense,
but how do you get the view information to show up after you've created the tpl.php file?

benced’s picture

Not sure if I understand what you are asking but...

When creating the new template file use page.tpl.php as the basis for your new template file,

example.com/myview will then be exactly the same as it was before you created the new file then edit this file with the changes you wish to make.

cerr’s picture

Hi Benced,

I have tried this but haven't been able to get my view page to override my site page.tpl.php. In particular: I have a page I can reach at www.mysite.com/mobile_special_events and a template like: page-mobile_special_events.tpl.php - I have cleared the caches but my custom template doesn't get loaded. Why not? What may I be doing wrong?

Thank you in advance for any hints & tips!

cerr’s picture

figured it out, the actually has to be page--mobile_special_events.tpl.php (mind the double dash) then it works just fine - that's for Drupal 7...

Ron

mithayes’s picture

Hi everyone just in case you have stumbled across this thread looking for a way to make a page template specifically for one view (or any other path for that matter) I have found that I need to put double hyphens in the template name to get this working.
ie:

example for www.example.com/label1/label2/label3/label4

the page template is page--label1--label2--label3--label4.tpl.php

I hope that helps anyone else out there scratching their heads trying to get this to work!

ericpai’s picture

I have the same problem.
I have a view called "video_by_category" with a path of "videos/category/%" the % is looking for a taxonomy term. A term can be "car". I want to create a custom page template for this view similar to page.tpl.php. I made some theme suggestions like page-videos-category, page-videos_by_category.tpl.php, page-views-view-videos-category.tpl.php, but nothing is working.
I got to mysite.com/videos/category/car and the view data is working but I don't know what page template it's using but it's not my custom on.

Is this possible?

thank you

Patroclas’s picture

The file name should look like this in D6

views-view--video-by-category.tpl.php

cedewey’s picture

There's a solid introductory blog post on this at http://www.ostraining.com/blog/drupal/views-templates/