A Drupal realization: Views rules
As an Ace in name only, I am only slowly realizing what the sharper cards in the deck have known all along: that for making "list of nodes" pages, Views is the way to go.
(I think I'll change my site's Mission now: "Drupalace.com: Bringing you the blindingly obvious since 2007.")
I've previously put lots of work into creating many a taxonomy-based list page, on many a site. Such as, for example, a primary link called News Articles, which returns a list of nodes which I've tagged with the terms "news" and "article". In Drupal terms, that'd be done by creating a menu item News with a path like
taxonomy/term/21,24
(See related discussion at Understanding node-list pages in Drupal.)
That's all fine; nothing wrong with creating lists that way. But I've always thought it an oddly clunky and inflexible method, and wondered why the Drupal gods hadn't polished it up more.
I realize now the wisdom of the Great Ones: the above method isn't the preferred way of making lists and isn't worth a lot of developer effort to make prettier. Views is the way to go. Views will make those taxonomy-based lists, or a boatload of variations, just as handy as you please – and with added features to boot.
Here's an example: adding header text to a Views list. That's a right useful thing to have – say, a bit of intro text for my hypothetical News Articles section: "The following news articles have been selected by educators for easy reading comprehension and kid-friendly explanatory graphics. They are recommended for elementary students, intermediate learners of English, and people named Dubya."
In the past, I had to fake headers like that. I'd make a node (Page, Story, whatever) with that text, tag it with "news" and "article" like other nodes I wanted to appear in the list, and check the "sticky" box. Voila, it would appear at the top of the list, looking for all the world like a header!
But it's a sham header, really just a node like everything else in the list. And then I'd run into troubles whereby some other taxonomy-based node list would, whether I like it or not, pick up that "header" node. For example, an All Articles list, returning all nodes tagged with "articles", would pick up that "header" node, even though it's not actually an article...
Views solves that. It offers a real header, unique only to that list. It's a thing of beauty (sniff).
Oh, and I just got myself jiggy with yet another Views trick: the Insert View module (http://drupal.org/project/insert_view). Make a node, put a special little tag in the text, and you get node + view – two great tastes in one! That's another fine way to add a header to a list, using the node to supply the header, and the embedded view for the list. The result may look the same as just ouputting the normal View with its own header, but it's a useful alternative when you plan further operations in which it's easier to work with a node than a view.
The Viewfield module (http://drupal.org/project/viewfield) looks like it may be yet another way of doing the same, without the minor bother of injecting a special tag into node text. (I dislike polluting actual text with input tags...) I'll have to give it a try.
Ah, my toolbox runneth over. Views, I'm feeling frisky. Let's you and me get a room.
(But let's not get cocky and think I'm actually starting to grok things. For example, "arguments" in Views: what's up with that? I have no idea what one would do with that.)













Re: A Drupal realization: Views rules
Thanks! It's obvious stuff for most users, but useful for beginners.
Post new comment