Is it possible to check view id/name from node template?

I prefer theming with node-nodetype.tpl.php, than with view-....tpl.php files,
so I'd like to use code like:

<?php if ($view == 'view-name'): ?>
...
<?php elseif ($view == 'other-view-name'): ?>
...
<?php endif; ?>

...

Is this approach possible?

Szy.

Comments

szy’s picture

No one...? :]

Szy.

szy’s picture

Status: Active » Closed (fixed)

Ok, thanks to seutje and marcvangend on irc... I know that is impossible in D6.

Closing... :/

Szy.

szy’s picture

Ok, thanks to seutje and marcvangend on irc... I know that is impossible in D6.

Closing... :/

Szy.

szy’s picture

Huh, I don't know why, what I was doing wrong before, but... magic - it works like
a charm now!

Example, how to easily theme your custom node type with thumb and title only
on front page - put in your node-yourcustomnodetype.tpl.php template:

<?php if ($view->name == 'Name_of_Your_View_for_Front_Page'): ?>

<h2><?php print check_plain($node->title) ?></h2>

<?php print theme('imagecache', 'your_imagecache_preset_for_front_page', $field_your_photo_field[0]['filepath']); ?>

<?php else: ?>

<?php your $regular (code (for a node)) ?>

<?php endif; ?>

It's a lot more efficient for me than playing with views' nested template.

:]

Szy.

merlinofchaos’s picture

The reason what you were doing before wasn't working was you were checking $view, not $view->name. The former is an object and will never equal a string.

dan.crouthamel’s picture

I'm using contemplate to provide the output for my custom node and I would like to know whether or not I'm in a view - views slideshow block to be specific. Unfortunately, this approach ($view->name) isn't working for me - it's empty. I must be doing something wrong :(

--- Update ---
Odd, I had a CCK Datestamp field in my custom content type. For whatever reason, the $view variable was not available. I removed the field and now it's there. Thought it was a fluke, so I added the field back and the variable is not available. Removed it, and it is.

szy’s picture

@Dan, there is a problem with latest releases of Date module. Check this issue to make
your with-date-views working again:

-> #348241: Upgrade to 6.x-2.0-rc6 causes node-view template suggestions to fail

Szy.

dan.crouthamel’s picture

Title: Theming views in node-nodetype.tpl.php » Thanks!

Ahh, thanks for pointing that out to me :)

merlinofchaos’s picture

Title: Thanks! » Theming views in node-nodetype.tpl.php

Title reset

lias’s picture

Good information, thank you,.