Download & Extend

HowTo correctly render fields on templates

Project:Dependent
Version:6.x-1.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hello Everyone,

I was wondering if someone could assist me in how to render fields on profile-node-form.tpl.php for dependent fields to work properly. (note: using content profile, cck)

I tested on Garland theme and the field hides and shows (works great!)
But on a custom theme I render field in my template file like below:

<?php
print drupal_render($form['field_example']['value']);
// more fields
print drupal_render($form);
?>

..and dependent fields seems to catch (the fields wont hide)
(note: i am experiencing the same issue with conditional fields with a new template)

I would really appreciate your help!
This is a great module and I would really like to use it on my website =)

Thanks!

Comments

#1

I can't be certain without seeing your entire content type and template,
but i think the code you posted above will render the same field twice,
resulting in conflicting DOM ids and breaking any further javascript processing.

And although it's technically valid, from my experience, you probably shouldn't be calling drupal_render in a template file.
drupal_render fires things like #theme and #process functions.
I'm not positive, but when called from the template file, I think it's too late, to use drupal_add_js for example.
This would obviously break any js-reliant functionality.

#2

aaronbauman - thank you for the comment. Does this mean that I should be setting all the variables in my template.php (I have about 50 fields in the form) and in my .tpl.php using

<?php
print $field_example;
?>
for each field?
I appreciate your help