Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By caschbre on
I've been creating pseudo fields (display-only) using the hook_field_extra_fields function as outlined in the blog post http://www.treehouseagency.com/learn/view-modes/extra-fields.
The blog post renders the output directly in code as opposed to using a template file. I've been trying to track down how I might go about rendering the output with a template file.
I wasn't sure if it would be something like field__extra-fields__some-identifier.tpl.php or if i need to add template suggestions.
Has anyone attempted this or have an idea on how to accomplish this?
Comments
Looking at the example, each
Looking at the example, each extra field is defined something like
The theme function would be defined in hook_theme() and can be defined to use a template file instead of a function.
Thanks nevets! I was able to
Thanks nevets! I was able to define a template file in hook_theme(). To follow the sample you posted, here's what it looks like.
Is there anything in addition to the 'template' option that should be included?
-
@foggyperspectiv | foggyperspective.com (blog)
Override module template file with theme template file
So adding the 'template' item to the array allowed me to create extra-field--created.tpl.php in the module folder. However, if I create a copy of that same template file in the theme folder it's not being picked up.
Any ideas?
-
@foggyperspectiv | foggyperspective.com (blog)
Did you try clearing the
Did you try clearing the theme registry?
Yep, I've run drush cc all
Yep, I've run
drush cc all
several times.Here's the whole code for my module.
The template file extra-field--date-box.tpl.php is picked up in the module directory but not in my theme directory.
-
@foggyperspectiv | foggyperspective.com (blog)
Visit the themes page. I've
Visit the themes page. I've had issues with Drush clearing the entire theme registry in the past.
I went to the themes page. I
I went to the themes page. I also went to
admin/config/development/performance
and cleared the cache there.So from the sounds of it the code appears correct and it's just tracking down why the theme isn't picking it up?
-
@foggyperspectiv | foggyperspective.com (blog)
Hi caschbre, Did you ever
Hi caschbre,
Did you ever work this one out ?
Thanks
No, I never did... and then I
No, I never did... and then I got distracted with other project tasks so I haven't come back to it. :-/
-
@foggyperspectiv | foggyperspective.com (blog)
Let #theme be handled by field
What worked for me was to let #theme be handled by field and simply change #field_name to my extra field name. The the field module would then pick my template in my theme directory.
template file: field--body_summary.tpl.php
J-F Bohémier
Angelicode.com