0

UPDATE: Although the answers below were correct, I ended up resolving the issue by editing the stylesheet to refer to those specific locations.


If I create a custom field and set it to hidden, is there any way I can call the values from those specific fields in the body?

For example if a field called color in an article is set to red, is there any way I can make the background of a div red.

  • 1
    Do you have added custom field to a content type?If yes, why you are not using hidden fields module. My idea I sue template_preprocess_page() and inside it grab value of your hidden field and then add your CSS class, the new added class will be available on the page template, add CSS colors as per your need – arpitr Sep 25 '13 at 20:37
1

Try what I suggested here: Getting a field's value from an entity

Replace field_get_items('entityform', $entityform, 'field_myfieldname')

with

field_get_items('node', $node, 'field_myfieldname')

1

Two methods I can think of. One is to use hook_nodeapi and catch the events of getting saved or viewed. Change the body field accordingly. You can also use hook_node_view.

I assume you want to change the bg of body field. Second easier way is to a use Computed Field. Now add two computed fields named "pre" and "post". Set "pre" to before body and "post" after body in the content "Manage Display"( pl. see the attachment).

In the condtional field "pre" insert the PHP code to take out color field value and print something like: "print ".

In the "post" field close the div tag: "print ""

I suggest you go through any simple Drupal book to get you started with the basics or do a course at Lynda.com.

You can always come back here and ask any question in case you have any query or need help in coding etc.

enter image description hereenter image description here

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.