0

I am very new in Drupal. I am using Drupal 7. I would like to create a custom rendering for a view I have created. Thanks to many posts found on the internet I have already done the following steps:

  1. Created a content type with Title and URL (it simulate a link list)
  2. Added 4 items of this content type
  3. Created a view which return items of my content type unsorted
  4. Thanks to the Theme Information link I have created a template named views-view--xxxx--page.tpl.php where xxxx is the name of my view.
  5. I have added the following code to the TPL file
<article id="node-123456">
    <header>
        <h1>Sample Title</h1>
    </header>
    <div class="content">
    </div>
    <footer> </footer>
</article>

And this works perfectly because I am seeing the Sample Title text when navigating on the page. I want now to enumerate the list of content item produced by the view but I dont know how to enumerate them. I have tried with

<ul>
<?php foreach ($rows as $id => $row): ?>
    <li><?php print $view->render_field('field_url', $id);?></li>
<?php endforeach; ?>
</ul>
0

Welcome to Drupal!

Use row level templating in template suggestion and follow exactly the same markup so your code should look like the following

<article id="">
    <header>
        <h1><?php print $fields['title']->content; ?></h1>
    </header>
    <div class="content">
    </div>
    <footer> </footer>
</article>

It will follow the same markup for each row.

| improve this answer | |
  • Hello, thanks for the answer. Do you mean choose a template on the section named "Row Style Output"? In the suggestions there is a template named "--xxxx--page.tpl.php". Does this means that I have to create a template starting with the dash? – Lorenzo Oct 28 '14 at 18:49
  • row level template basically style each of your row. If you want to add markup to your views row go ahead and copy exactly the same file and clear the cache – Shabir A. Oct 28 '14 at 18:51
  • Sorry but did not understand your suggestion. Could you please be more specific? I cant understand if I have to change the view name or the code somewhere. Thanks – Lorenzo Oct 28 '14 at 18:57
  • A view is a list of rows like <div></div> <div></div> <div></div> If you want to markup your individual row then override that template and add your markup. You don't have to change view name just pick row template from template suggestion and add your markup there. Remember markup will get applied on each row! – Shabir A. Oct 28 '14 at 19:06
  • Ok. I have got it now. Thanks. Unfortunately my theme does not have a row style template. In fact if I click on the Row Style Output hyperlink I get the message "This display has no row style theming information" – Lorenzo Oct 28 '14 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.