7

I have a view with several 'Global: Custom text' fields. These are actually just serving as place-holders, and I'd like to create a field template file for each, that essentially places some custom html/php when it encounters these fields in a view.

Almost everything is in place and working... except, I notice that Drupal automatically gives the id of 'nothing', 'nothing_1' etc to its global custom text fields. So, if I have more than one of these global text fields and would like to create a separate field template for each, I'm presented with a problem.

I'd have to name my template files views-views-field-nothing.tpl.php etc. This is undesirable, because I want to reuse these field templates throughout my site. I shouldn't have to worry about ordering these global fields just so in my views, so that the one I expect to be nothing is 1st and gets that id and the one that I expect to be nothing_1 or nothing_2 gets that id...

Has anyone run into this issue before? Any ideas whether I can set my own field-ids for global custom text fields in views, so they don't all have those generated id's? Is there a module that does this out there? My searching hasn't found anything yet.

Thanks for any guidance!

p.s. The reason I'm doing this is because I'm trying to put some html in my view (like <fieldset>) that is getting stripped from the views fields, so I need to do it in a template file.

3

Well, sometimes the only way to solve a hard problem is to write your own module (or, as in my case, just collaborate with someone who's already writing such a module).

I'm now using the newly-launched Views fieldsets module to achieve what I was trying to do!

  • Nice, I will be sure to test this module soon, seems applicable for a number of scenarios. – Duncanmoo Jul 17 '12 at 7:34
  • It seems like a views-specific approach to something Display Suite solves with its different Displays. Keep in mind that DS can add custom "fields" to the displays, even blocks or custom PHP. – Capi Etheriel Jul 17 '12 at 10:08
  • Thanks, barraponto. You make a good point. I'm using views because I'm implementing a 'searchy' type of interface with exposed filters, but it's good to keep DS in mind too! – Boriana Ditcheva Jul 17 '12 at 13:18
2

I am not sure if this is a good solution, but I came across the same issue with those template file suggestions. What I did was work around it:

  1. hide all fields by checking "Exclude from display" on each.
  2. add one 'Global: Custom text' field at the end of the field list put the [fields] into the HTML structure you want
  3. Remove or override field & wrapper style settings

May be a solution for you? Another replacement for 'Global: Custom text' field is to use the views_php field.

  • Hey Duncanmoo, yes, I thought about what you're saying, but if you look at my p.s., the code I wanted to put gets stripped out of the views fields because it includes <fieldset> tags... that's why I felt I had to use templates. Views php field may be an option, I just wouldn't be able to re-use this throughout the site as easily then. I'll check it out. +1 for the suggestions. Thanks. – Boriana Ditcheva Jul 13 '12 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.