I know there is a slim chance of being able to do this with Views 2 core, but this is something I really need to try to accomplish.

I have a somewhat long view that is a food menu for a restaurant, I need to put id tags where the taxonomy grouping occurs so that I can use my sub-menu to jump right to the 'bookmarked' id section.

The specific page view can be seen here: http://d430602.u51.quantumized.net/menu/delivery-menu | Each heading is generated by views using a grouped taxonomy term. Ideally, I'd like to auto-generate a id="term#" with the tax term so that I can create the bookmarks to jump to that section. Is this possible in any way?

I have achieved the effect with the 'dinner menu', but it uses many attachments and I had to hard-code the id tags into the headers. This works, but is ungraceful and defeats the purpose of the CMS. Long views with many attachments will be very hard to organize and maintain.

Any ideas?

Thanks~

Comments

merlinofchaos’s picture

Status: Active » Fixed

Assuming you're using the unformatted style, override views-view-unformatted.tpl.php for your view. The $title is printed in that template (or whichever style you're using for this) -- you can re-format that into an anchor and/or link as you need. It may require a little effort to reformat the link text into something suitable to use with an href, but views_css_safe() might be a decent start. Maybe with a strtolower() as well.

3cwebdev’s picture

Works like a charm! Thank you so much (again) for the help and tips. Views and it's template system is awesome :)

merlinofchaos’s picture

Category: support » task
Status: Fixed » Active

This probably needs to make its way to the handbook on the Snippets page.

3cwebdev’s picture

Just for reference, in case anyone else is looking for a similar solution. Uses the first word of the title, converted to lowercase.

Example output:

 <h3 id="bookmark">Title</h3>

The code I used in views-view-unformatted.tpl.php:

<?php if (!empty($title)): ?>
	<?php $words = str_word_count($title, 2);?>
	<?php $bookmark = array_slice($words, 0, 1);?>
	<?php $bookmark = implode(' ', $bookmark);?>
  <h3 id="<?php print strtolower($bookmark);?>"><?php print $title; ?></h3>
<?php endif; ?>

<?php foreach ($rows as $row): ?>
  <?php print $row ?>
<?php endforeach; ?>
merlinofchaos’s picture

Title: Generate ID in output of view? » Documentation: Add a snippet explaining how to provide anchors for groups in theming
merlinofchaos’s picture

Status: Active » Closed (won't fix)

If it hasn't happened in a year, it probably won't happen.

3cwebdev’s picture

Status: Closed (won't fix) » Fixed

This snippet has been tested and added to the Views snippet documentation: http://drupal.org/node/588804

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.