Hello All
I have embedded a view in page-node.tpl.php. The view should only be displayed at node page (e.g www.example.com/node) but it is displayed in all pages that have node in their address (e.g www.example.com/node/add). How is it possible to bypass all node pages except the main one (www.example.com/node)?

Kind Regards
Ali Majdzadeh Kohbanani

Comments

iimitk’s picture

Use the arg() function:

if (arg(0) == 'node' && arg(1) == '') {
  // Include your view.
}

By view, you mean a Views module's view?
________________________
"Creativity is knowing how to hide your resources" - Albert Einstein.

Ali Majdzadeh Kohbanani’s picture

Mr. T
Thanks a lot my friend. Yes, I mean a Views module's view.

Kind Regards
Ali Majdzadeh Kohbanani

iimitk’s picture

If you've built a view as a page view, then why embed it in the first place? Views 2 allows you set the page path arguments by default.

After you set up the default view values & settings, add a 'page' display from the left-hand menu in your view settings page.

Then scroll down to the 'Path Settings' box and click on the 'None' link next to 'Path' to define the view's page path arguments. You should use the % placeholder for dynamically generated parts, e.g. node IDs.

Also, for the method from node-page.tpl.php, the correct code should be:

if (arg(0) == 'node' && isset(arg(1)) && is_numeric(arg(1)) && arg(2) == '') {
  // Include your view.
}

This would include the view on pages like node/% only where % is a node ID. Check the documentation for arg() for further info.
________________________
"Creativity is knowing how to hide your resources" - Albert Einstein.

xmacinfo’s picture

I believe you mean the front page. For this you need to duplicate the "page-node.tpl.php" and rename the copy to "page-front.tpl.php".

Ali Majdzadeh Kohbanani’s picture

Xmacinfo,
Hello
Thanks for your response. No, that is not front page, because I am using the front page module and I have created a splash page as my front page. Hence, I need to redirect users from the splash page to the main site, more specifically to the node page (www.example.com/node).

Kind Regards
Ali Majdzadeh Kohbanani

Ali Majdzadeh Kohbanani’s picture

Mr. T
Thanks. Problem solved. I had managed to solve the problem using the $head_title variable which is accessible in page.tpl.php but your solution is much more elegant. Thanks again.

Kind Regards
Ali Majdzadeh Kohbanani