0

I created a view (page name 'Archives') to load the following values from all the posts of a particular content type.

Year = field_year
Volume = field_volume
Issue = field_issue

By using views I couldn't get the desired output. So, I created a template file (views-view--archives--page.tpl.php) and wrote the following code. Please see the attached screenshot & code below. Please help me in correcting the code. This would be a great help. Thanks

<ul>
 <?php foreach ($view->style_plugin->rendered_fields as $delta => $item): ?>
  <li>
    <span class="view-header"><?php print $item['field_year']." (volume - ".$item['field_volume'].")"; ?></span>
    <span class="view-issues"><?php print "Issue ".$item['field_issue']; ?></span>
  </li>
 <?php endforeach; ?>
</ul>

I need the desired output, please help

1
  • The template page--archives.tpl.php will be used to create the overall page structure when you goto www.example.com/archives, so the output of your view will be placed in the content area/region in the page. Are you needing the Year field somewhere else on that page? If so where and in what format, eg rendered or raw or?
    – Jimajamma
    Commented Feb 2, 2014 at 12:44

2 Answers 2

1

You should use the Views templates (under Advanced > Other > Theme: Information). It gives several output types. When you create a Views specific template file, it passes a whole bunch of variable/values that you have chosen in your Views to the Views template file. Then you are free to use it like how you want. Read more info at http://views-help.doc.logrus.com/help/views/analyze-theme

1
  • Thank you Sridhar, this helped me in reaching near my goal. but it has a problem. Please see the above modified question and the screenshot. Please help. Commented Feb 2, 2014 at 14:50
0

You shouldn't need to write a template. This can be done in the views UI.

Click on the year field and select Exclude from display. Then click the volume field and override the output. Using replacement patterns it should be something like [field_year] [field_volume]. Then click settings for your display and select Group by field_volume.

See https://drupal.org/node/1565480

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.