2

Using the blog module, I'm setting a custom template for the individual blog articles (node--blog.tpl.php) which contains a list item and the content inside.

However, I can't figure out where I should be putting my wrapping <ul> tag? If I put it in either page.tpl.php or region--content.tpl.php then the entire page content is (understandably) wrapped including pagination and other elements. I just need to wrap the list items.

Thanks and please be gentle with a newb :)

EDIT: code

page.tpl.php

...
<?php print render($page['content']); ?>
...

region--content.tpl.php

<?php if ($content): ?>
 <div class="<?php print $classes; ?>">
  <ul class="blog-list">
   <?php print $content; ?>
  </ul>
 </div>
<?php endif; ?>

node--blog.tpl.php

...
<li>
 #content#
</li>
....
4
  • 1
    This question appears to be off-topic because it is about code you wrote, for which you want to write better code, or you want to understand why it doesn't work, but you didn't show the code you are using, or the part of the code that is relevant for the question. See Help Center.
    – Mołot
    Commented Jun 8, 2014 at 13:34
  • @Mołot Apologies, I've now added my code. It's core Drupal stuff (using Zen theme). I need to work out where to put <ul class="blog-list"> so it correctly wraps only the list items (being populated by node--blog.tpl.php. Thanks Commented Jun 8, 2014 at 13:45
  • it should be node not the page or region
    – M a m a D
    Commented Jun 8, 2014 at 14:38
  • @Drupalist I'm using a custom node template (node--blog.tpl.php) for each list item but I need to wrap all list items in a <ul> tag. Commented Jun 8, 2014 at 15:00

1 Answer 1

0

Taking a guess that you're talking about the /blog page, the content is built in blog_page_last(). The nodes themselves will be in $build['nodes'] when that function returns.

As with pretty much everything in Drupal there are a bunch of different ways to alter that content; I think the easiest in this case would be to use hook_page_alter():

function MYMODULE_page_alter(&$page) {
  if (current_path() == 'blog') {
    $page['content']['system_main']['nodes']['#prefix'] = '<ul>';
    $page['content']['system_main']['nodes']['#suffix'] = '</ul>';
  }
}
2
  • Added to template.php and that worked - thanks Clive! Thanks for the link to the docs - I'll have a read through to try and better understand. This seems insanely difficult for the sake of two HTML tags. Commented Jun 8, 2014 at 15:35
  • Welcome to Drupal, where a complicated website will take you about an hour to build, and changing a few HTML tags will take about a day and a half ;) If I could suggest some more reading, Render Arrays will help to understand what's going on with the $build that gets returned from the blog function, and what the #prefix and #suffix stuff really means
    – Clive
    Commented Jun 8, 2014 at 15:37

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.