3

Sorry for any incorrect terminology; I'm new to Drupal so it's possible that I'll mess up the Drupal-specific vocabulary.

I'm putting together a View->Page with a Table Format.

I've got a field in my data set called "registrationdate", and I can display that just fine. However, what I need to display is registrationdate plus 14 days. I haven't been able to figure out how to add a number of days to the value so I can display the adjusted value.

I know how to do this in SQL, but since Drupal acts as an abstraction layer between me and the database, I can't do so in this case.

Thanks in advance for your help.

1 Answer 1

2

You can change the value using a field template.

  1. Add the date field to your view
  2. Look in Advanced -> OTHER -> Theme: Information for a suitable file name for a field template that will only affect the field in this specific view. They are listed in order from least specific to most specific so the final one in the list for that field is probably the best one to use. The link on the filename will show you the default contents for such a file.
  3. Create a file in your theme where you keep template files with that filename
  4. Start with the default contents in that file and refresh your cache
  5. Install devel module and use dpm($output) in your new template file to see the structure of the output
  6. Use PHP to edit the appropriate portion of the output, you may need strtotime() and date_add() to achieve this.

Clear your cache often. If you haven't already got drush installed, do it, it is a very useful tool.

4
  • Thanks for the help, I'll give that a shot early next week! Feb 15, 2015 at 2:25
  • I've been working on putting your suggestions into place, thanks again! I do have a question about modifying the template, however. Namely, doesn't modifying the template modify every field that's rendered, everywhere in the system? I'm seeing the test text that I put into the template in lots of various places throughout the site. Feb 18, 2015 at 22:34
  • 1
    That depends on which template name you use. views-view-field.tpl.php will affect all fields in all views, while views-view-field--viewname--displayname--fieldname.tpl.php will only affect the specific field in that particular display on the view you specify. There are a bunch of others in between that are different permutations of that.
    – Darvanen
    Feb 18, 2015 at 23:07
  • Oh, very cool, thanks for telling me about that! I'll dig into the docs in that area. Thanks again! Feb 20, 2015 at 0:57

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.