0

I have some hierarchical content and I am trying to customize the output. I am trying to output a table something along lines of

Lesson Title    Description

 Exercises in Lesson    Exercise1
                        Exercise1 Description
                        Exercise2
                        Exercise2 Description

I looked at the existing display output template, expecting it to generate the view output. But that is not the case. I need to find the right file to edit, to add the PHP code to build my customized table.

Any ideas?

Thanks

3
  • Wasn't there format->table on the right in views settings?
    – Mołot
    Oct 3 '15 at 16:22
  • There is, but I can't figure out if I need to make my customizations in one of the view templates (such as style output) or if I should add a function in template.php (as described about 15min in here Oct 3 '15 at 17:26
  • I added an updated section to my answer for which one to choose for that particular part, using a template file or an override function. You may or may not find it helpful but hopefully helpful. Oct 3 '15 at 18:42
2

There are quite a few ways to find this information, most of them are pretty easy to accomplish. I'm going to list a few different ways that I usually include in my process. (See update below for the choice to use template suggestion or template.php override function)

Theme Debug

Read here: https://www.drupal.org/node/223440#theme-debug

When turning on theme debug you can inspect the HTML of the page and you will see the templates that are actually used and template suggestions for the markup of the page. The Drupal gods blessed us with this one as of D7.33, so it won't work on anything before that.

Views Theme Information

There are quite a lot of little tricks built into views to help developers. One of them is the ability to see what template file is being used for a particular view.

This is where the magic is for the template files being used. Views theme information

This is what that modal shows. Views template files

Read here for more in depth documentation of each particular template file and what it does exactly.

Notes:

From your question and your layout of what your view is doing or trying to do (only speculation, so take this with a grain of salt, the more information given the easier it is to answer these types of issues) you are using views grouping of some sort to achieve that layout or hierarchical display of information. Views grouping is a little bit different than the regular template files as it uses a registered theme function for that, which is better for performance but you can still override with a template file as well. You can find that template file here if you think that may help in your current situation. I know that there are a lot of ways to skin a cat and a Drupal page so I could be off on that assumption. If I can add anything more to help just let me know.

I haven't watched the video mentioned in the comments yet but if I see exactly what that is referring to I will add some more information about that. You can also search for custom view handlers and other cool custom view options to achieve basically anything a BA can imagine.

Update:

I watched the video from the comments. I'm guessing that is fairly important to you since you mentioned it specifically in the comments on your question. Just to be clear for future readers incase the video is ever lost or deleted, OP is asking if he should use the template override (as in getting the template suggestion and copying the file to your theme/sub-theme and changing it from there) or overriding the template file in a function in your themes template.php. I have seen either way used before but there is a rule of thumb to use for this, if you are doing a major logic change of some sort use the override function in template.php. If you are only making basic markup changes and small data display changes you are safe to just use the actual template file. I will go ahead and say that on larger projects the amount of template files can get pretty large and unruly so unloading some of that in your template.php (even better broken out into inc files, see Bootstrap/Zurb themes for examples of breaking pieces out) helps out in some cases, but besides the rule of thumb mentioned that is up to you as the developer. (I haven't ever been told any different or read anything in Drupal standards as to say which way to go on this one besides the basic rule of thumb I mentioned and I consider myself pretty high up there with wanting/needing to follow Drupal standards, if anyone has any more information on that please chime in)

1
  • Great info, thanks. The theme debugger sounds excellent. Yeah, I am using a grouping (but am starting to wonder if attachment would work/be better) per [this post] (drupal.stackexchange.com/a/176210?noredirect=1) I will dig deeper into your suggestions. Thanks again. Oct 3 '15 at 19:09

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.