I usually find what I need in here without asking question but this time couldn't find anything.

I have a view which lists documents from a file field of one of the content types. This content type (Info Page) has a Title, Body, and file field. The file field can take up to 10 PDF documents. The end result is a list of all documents attached to all published Info Pages and each item is a direct link to the pdf file. These documents will be updated quite frequently and I want to make the update process as smooth as possible.

Here is what I'm struggling with. The names of the files attached to the document will have hyphens/dashes instead of spaces and possibly some other characters/words I would like to remove. I don't want the user to provide another Text in another field, instead I would like the link title to be generated form the file name with some characters substituted for spaces and possibly some words removed. Does anybody know of a module which would have such a functionality?

Help would be much appreciated. Thank You

Drupal 7.33 Views 7.x-3.8

2 Answers 2


Have a look in your view under Advanced -> OTHER -> Theme: [Information].

You'll see each field can be themed separately either across the board or in a set of themes, or on a specific theme, pick whichever file name best suits your needs and add a new file to your theme's template folder with that name.

You can use the link on the field name in that window to grab the default starting point for that field and then edit it.

Once you've created the file and put the default text in it, start playing around with preg_replace(), this uses regular expressions to replace certain characters. Here's a starting point, it replaces hyphens and underscores with spaces in the $output variable (I think. My regex is a bit shaky):

preg_replace('/-|_/',' ',$output);

Use Views "Rewrite" functionality. You can rewrite every field when formatting it in the view field settings (look for the "Rewrite" collapsed field set after the label setting and open it up).

There you can use tokens, your own html, etc to create custom output. No PHP code is required.

NOTE: tokens are only available for fields above and including the one where you are rewriting. So rearrange fields so the one you are rewriting is last. And set the fields above to "exclude from display" if you'll be using its token in the rewrite (unless you want its value displayed twice).

In addition, do check out the Filefield Paths module. I can help you with renaming files when they are uploaded.

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.