0

I have a custom text field which I use to display some voucher code to users. I have it in a custom content type named (machine name) : 'add_deal'.

What I want to do is to style the field when the node is displayed and add a link/button next to that field to copy the text in that field.

I created a field--field-type--cotent-type.tpl.php file, but how do I use it, and I dont think its working for me either. Is there any hook function I need to use to make use of that tpl file?

How could I achieve it?

1 Answer 1

2

I think you have to use your field name instead of field type in the name of your .tpl.php file. Assuming the label of your field is 'Voucher code', then the machine name of this field would normally be field_voucher_code and your template file should be named field--field-voucher-code--add-deal.tpl.php See theme_field documentation for more details.

Don't forget to clear the caches (i.e., rebuild the theme registry) after creating this file in your (custom) theme.

3
  • yes I was using the name instead of field type, I cleared the cache and it works now. NOTE: There shouldnt be any underscores in the tpl file name, drupal converts underscores to hyphens. Thanks for the comment though. Jul 19, 2015 at 22:56
  • Ok, good to hear your problem is solved. Edited the answer, you're right about the underscores.
    – Watergate
    Jul 19, 2015 at 23:05
  • You still have content type name with underscores, once you rectify it I will mark your comment as answer :) Jul 20, 2015 at 5:58

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.