Hi,
I've been playing with Drupal for a while and I'd be interested in rendering various CCK fields using their widgets in my custom blocks and ctools panes.
For instance, I'd like to render CCK FileField files ina block and I was expecting a theme function to do it for me but that didn't work.
I tried:
$out = theme('upload_attachments',$node->field_myfiles[0]);
$out = theme('upload_attachments',$node->field_myfiles);
eventually I did it manually:
$out = "<div>" . theme('filefield_icon',$node->field_cv_myfiles[0]) . l($node->field_myfiles[0]['filename'],$node->field_myfiles[0]['filepath']) . "</div>";
How does the ['view'] property get rendered?
I've been looking for reference documentation but I can only find theming information.
I'd also be very interested in rendering a whole CCK group or fieldset by code instead of doing the fieldset myself and pulling all the contained fields, checking the permissions for each one.
Any direction would be appreciated.
Thanks!
Comments
_
Maybe checkout how the cck_blocks module does it?
Thanks! That was a very good
Thanks! That was a very good hint.
I had came across drupal_render() but didn't know how to send the parameters to.
I'll continue researching, but that was a good start. cck_blocks is a little module, easy to understand.
I'll keep digging as I want to render content for users that don't have access to those fields, but I think it will work out eventually.
just for the record:
Just for the record, I don't understand why they don't use instead
Anyway, then you can do:
In order to force CCK fields
In order to force CCK fields to be rendered, the simplified code should explicitly set
build_modeto 'full node':To hide the label when rendering the field, append the following:
And to display raw formatted values...
When you want to display CCK field values without the surrounding DIVs:
You can then access your individual formatted field values as such:
fields with multiple values
I was a little confused at first looking for an html render of a field that allowed multiple values. While $node->field_myfield[0]['view'] allows you access to the html for one of the values in the field, you can access the group of values rendered in $node->content['field_myfield']['#children'].
Golden
Thanks for this post. Knowing how to render nodes manually is golden.
Thx infojunkie!!! U saved my
Thx infojunkie!!!
U saved my day by sharing this post.
I tried doing exactly that in
I tried doing exactly that in my preprocess_node() in template.php but get an empty string:
If I do the same in a hook_preprocess, I wind up with infinite recursion.
thanks been looking for this!
thanks been looking for this! using panels and page manager from chaos tools and it stops me from using rendered children of cck fields, this made it work again! thanks!