2

Try to figure out when field templates are the wrong approach...

I've been told and agree that you should ultimately avoid creating node templates and try to process things before they hit the theming layer. I believe this because you alway want to add more room for theming later, and data changes should stay with the proper entity... at least a field template if not template preprocess, nodeapi, etc.

So... if I have a node type that's requiring I end up with 3-5 field templates, to do some logic on the display of links vs. text, add standard suffix text, etc. When do I throw in the towel and just do it all in the node template because that's the right thing to do?

Maybe I just need contemplate?

Your thoughts?

1 Answer 1

2

I would never recommend Contemplate to someone who needs true control over the output.

Here is what I usually do:

I make php stuff and logic stuff on the node_preprocess, only sending to node.tpl variables ready to be echoed, or arrays to be foreach'ed and then printed, in the case of cck fields with multiple values.

And I never run functions of any type on node.tpl.php. If you need to run a function, run it on preprocess!

Using this approach my templates become faster, as they can take take a little more advantage of the internal template caching system, and also, my node.tpl.php gets REALLY easy for me and others to understand it.

1
  • Thanks. I ended up using the field templates... they are all single value image fields in which I need to test other link fields to determine if they are linked or not. Plus adding conditional suffix text, etc. Custom Formatters seemed the other option, but I'd rather put any node in a file. Wish I could have preprocessed all of it, but the data just wasn't quick available. Or rather the node objects were so disgusting I couldn't get at what I needed.
    – doublejosh
    Commented Jun 2, 2011 at 9:16

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.