1

I have a field, foo, set to "Exclude from display", and output later in a "Global: Custom text".

I need to control the rendering of this field based on a different value on the same node. I thought I could just implement a template file like:

function THEME_views_view_field__VIEWNAME__DISPLAYNAME__FIELDNAME($view, $field, $row) {
  $output = isset($bar) ? $foo : $baz;
  return $output;
}

But as soon as I add this function to my template.php file, I loose all output instead. No matter what I return, I get nothing. I tried trivial things like

return 'AAAAA';

to no avail. I'm probably doing something very simple wrong, but looking at my own previous attempts to do similar things in the same template file, I can't see what's wrong. Yes, I've cleared the cache numerous times.

1
  • So I thought that I was doing something fundamentally wrong here, and my question was generally asking "How do I do this right". I'm not what changed, but simply messing with a few Views settings and reverting them, fixed the issue. My best guess is that at some point, Views accidentally saved "bad" data, which caused it not to pick up the right templates. Now I'm not sure what do to with this question, can it have a correct answer?
    – Letharion
    Jan 23, 2012 at 10:28

4 Answers 4

2

I don't know if this is the answer you wanted, but I template the individual fields by templating the custom:global, and accessing the individual pieces through the $view object.

2
  • That sounds like it could be useful, but unfortunately I don't think it will help me as my problem is that I can't seem to template at all.
    – Letharion
    Jan 21, 2012 at 21:19
  • Recheck the template name... use the suggestions from the View UI when you click on 'templates'. Remember to refresh the cache. What does the View UI say about templates used? What does devel say?
    – nstruong
    Jan 23, 2012 at 3:22
1

Is that in your template.php? Why not just override the tpl.php file being used to generate the output and do it there.

1

If you use Display suite module, you can write php code in "Global: Custom text". Perhaps, it will help you.

0

I thought that I was doing something fundamentally wrong here, and my question was generally asking "How do I do this right". I'm not what changed, but simply messing with a few Views settings and reverting them, fixed the issue. My best guess is that at some point, Views accidentally saved "bad" data, which caused it not to pick up the right templates.

I was recommended by a moderator to accept this as my own answer, but I will up-vote the others, as all suggestions were helpful. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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