Let’s say you have a view in which you take in an argument you use for filtering content. That’s very easy, but what if you also want to display, say, “Most Recent {ARGUMENT}” before the list of content? It’s not as easy as it seems like it should be. It would be nice if there were a token-based solution, but the best way I can find is to use PHP in the view header.
You’ll need to enable the PHP Filter module, which is a core module that comes with Drupal.
I got this method from this comment, but I thought I’d repeat it here so that it will be easier to find for someone in the future. This takes the argument, turns the ‘-’s into spaces, and capitalizes every word. You may only want to do some of that, or something else, but it demonstrates how to get the argument to do with what you wish.
$view->args
is an array of the arguments in the request.
Here’s the code:
<h2>Recent
<strong>
<?php
$view = views_get_current_view();
print ucwords(str_replace('-', ' ',$view->args[0]));
?>
</strong>
</h2>
Do you know of a better way? Maybe one without having to use raw PHP in your view? That’s what the comments are for! (and thanks)
Yesterday I wrote that I am going to be learning drupal by developing an online user-generated marketplace. I’ve started the odyssey, and I’m ready to report on the progress I made in Day 1.
My References
Whenever I’m learning a new system, I drown myself in reference material. Here are the resources I’ve used so far that I’ve found the most helpful:
- Drupal Concepts is a list of common concepts to understand before getting started with Drupal. It is a must-read before you get started to avoid confusion.
- General Category is where I turned when I realized I didn’t understand the terminology many guides were using (which was almost immediately).
- Building a Website with Drupal is a series of blog posts I’ve found very helpful so far in getting started. It sometimes covers things in more detail than I need, but it’s aimed at an audience a little less tech-savvy than me.
- Top 10 must-have Drupal Modules is a top-10 list that’s actually useful. I’m currently using 7/10 modules listed here.
Features of the Marketplace
It’s time to decide what I really want the site to do. A “user-generated marketplace” is pretty vague as far as website requirements go, so I decided to list out some features I think I want. The ones with asterisks are crucial. Also, this list is tenative. I may add/subtract features at any time:
- * I’m going with the Envato method of payment, and a more traditional one. The user can upload some money into his/her account, and then will be able to buy things on the site without having to check out, or they can buy things the “normal” way with a checkout process.
- * Carry digital and physical goods
- Digital goods have an unlimited inventory, but the user has to pay before downloading.
- Physical goods have a limited inventory (I’m only allowing a user to sell 1 of any item at a time), and once the customer pays, the seller is notified
- Package tracking for all physical goods
- User profiles with pictures, bios, etc…
- * A category system for navigating through items for sale
- Buyer/seller feedback
- Rating of items (1-5 stars)
- Private messaging system
Now on to Drupal……
Installing Drupal and Some Modules
I’m not going to list every step of the install. There are plenty of places for that. Instead, I’ll note interesting tidbits and gotchas.
The install went through without a hitch. I had a basic site staring me in the face after only a few minutes.
Now it was time to start installing modules and getting some basic functionality going on. It’s amazing how much functionality you can get for “free” (no coding) using pre-made modules, and I haven’t even scratched the surface of the gazillions of them.
Here are the modules I’ve installed so far, and (if necessary) a brief description of why:
- CCK – Apparently, you always need CCK. Always.
- Views – I haven’t used it yet, but apparently it’s another essential
- Pathauto
- Admin Menu seemed convenient
- XML Sitemap because it’s never too early for SEO
- Token is needed by Pathauto
- Poor Man’s Cron because I am lazy
- Voting API is needed by Fivestar (below)
- Fivestar makes voting on things easy
- Location for entering where a physical item will ship from
- SMTP Authentication Support because PHP’s
mail() function wasn’t working and I didn’t feel like figuring out why
- A note on this one: I had to change line 246 to
require_once(drupal_get_path('module', 'smtp') .'/phpmailer/_acp-ml/phpmailer/class.phpmailer.php'); because the path was wrong originally
- Image
- Flag for flagging items
- Advanced Help because I’m a n00b.
That seems like a lot of modules to me, but then again they each serve a distinct purpose, and I haven’t had to code at all.
What I’ve Got So Far
I created two new content types: Digital Item and Physical Item, and added some custom fields to each. Right now, they contain all the data they should, and they are displaying on the front page, but the display is ugly, and I want a different front page.
But, without any code, I’ve created 2 item types, and added some sample items. I can vote on them, or flag them as somehow bad. I can comment on them, and view where a physical item will be shipped on Google Maps and the best part is….
I haven’t written a line of code!
What I’ve Learned
I’ve learned a lot already, and I haven’t even done much:
- Reading up on those first few references and figuring out what modules, nodes, taxonomies, blocks, etc… are has really helped my digest the rest of the help material.
- Every time you add a new field type, you have to go and edit the user permissions to allow an authenticated user to edit that field type. If you don’t, and you add that field to a content type, the user will not be able to use it when creating a new item.
- Always read the README.txt and the INSTALL.txt if there’s any even minor problem installing a new module.
Next Steps
I’m going to put off theming the site until I have all the functionality I want. I may get a pre-made template, but I’m not doing anything custom yet. Next up is creating user profiles and setting up the category system (taxonomy). Additionally, I may have to play around with views to start setting up the actual flow of the site.
Wanna tell me how much of a n00bcake I am? The comment section is all yours!
Once again I emerge from my hole and post another incredibly infrequent article with the promise of more frequent ones to come. But this time I have a plan… kinda.
I’ve discovered I have a medical illness. It’s scary and you probably have it without realizing it. It’s called “IDontKnowDrupal-itis” and it affects millions of Americans. But I’m here to do something about it, and you can ride along with me. I’m going to beat the disease, and so can you!
Over the next few days, I’m going to be jumping into Drupal head-first by creating a pretty elaborate user-generated marketplace site. “What’s a user-generated marketplace?” you head-scratching, non-banjo-playing people may ask? It’s sorta kinda like Craigslist, but not really. The best site to compare it to is a place like ThemeForest, or iStockPhoto. It’s a place where users can upload digital (or real, in the case of Etsy) content and sell it, with the owner of the site taking some percent of the gross sales. It’s a model that’s getting big, and it’s a not-too-simple (blog), not-too-complex (Google) type of site to start out learning a framework/CMS on. It’s going to have some pretty cool and unique features, too (I hope).
So stay tuned for lots of Drupaly goodness, and plenty of laughs as you watch me flounder about like a madman in a sea of sanity.
Got something to say? WELL NO ONE CARES! Except for me, so let me know…