How important is trendiness of the research one works on?
At least focus on your interests versus your advisors.  We get a lot of questions from weak reeds who just bend with the wind.  But at the end of the day, there's a huge investment of years by junior researchers in these projects.  Need to do something you want to do.  Exercise choice during advisor and project selection, stick up for yourself, etc.
Obviously it's a multivariable function (not just x and y, but some z's and w's floating in there).  So, you should look for something both marketable AND interesting.  While, it is unlikely that optimizing for one variable will optimize for the other, there likely are several areas where you can be both interested/skillful AND that are marketable.  Yes, absolutely you have to use your noggin when deciding this...and your advice to a younger you is relevant.
I would be wary of something that is trendy now if it has the seeds of changing soon.  String theory, nanoscience, machine learning, etc.  At least don't get involved in one of these rush areas if you aren't super interested in it (I don't believe the students who all come here and say they have a "passion" for machine learning--they have a passion for getting hired by Google.)  
I think often there is a lot of opportunity at field boundaries (and has been for decades).  "Material science" is the classic example.  If you can collaborate, it opens up possibilities and often you find others can't really compete as well in the border areas (are only able to work in the core). Personally I find that a lot of fun (and also doing applied work)...so it's not even a sales BS job for grants, like with some researchers.  I really like it.
It's probably good if you can package yourself as both a specialist and a fundamentalist.  I.e. I'm the math expert in some bizarre shale oil krieging junk.  But I also can find a home as a graph theory math person (I'm making this up...not sure if those are real things...but you get the idea).  Have some sexy thing like that specialty...but also make a department feel comfortable that you can teach basic classes and fit in with the core math department.
This is not to say there is no demand for people drilling down the center of the field.  But you better plan on being the best, then.  Really top notch.