Borrowed from the fences project: set the field template on instance level - doesn't add any database tables or so, uses the instance settings which are called anyway every page callback and is cached.

The patch also adds another suggestion after the function, namely the field template itself. Eg, if you chose the minimal template, this would normally call theme_ds_field_minimal() (this can't be changed alas, that's old cruft from the past) but there's not an easy way to override this with a template file. However, the patch adds a new suggestion by stripping of 'theme_ds_field_' and just adding 'minimal' so you can create field--mininal.tpl.php (field.tpl.php must be in your theme directory as well, don't forget that).

So you get this now as suggestions on say for instance a body, first four are core, last 2 from DS.

- field__text_with_summary
- field__body
- field__article
- field__body__article
- theme_ds_field_minimal
- field__minimal <-- in case the tpl file exists, that one is used \o/

So now you should be able todo this:

- enable field templates and select the global default field template
- set the default field template on instance level of a Field API field.
- override the default field template configuration from instance level on view mode level
- or just override the global default template on view mode level per field

Settings this to needs work because

  • Need feedback if that last suggestion is ok enough, maybe I should others as well ?
  • Needs a lot of testing and also simpletests as wel
CommentFileSizeAuthor
#2 1299580-2.patch3.72 KBswentel
#1 1299580.patch3.72 KBswentel

Comments

swentel’s picture

StatusFileSize
new3.72 KB

And the patch

swentel’s picture

StatusFileSize
new3.72 KB

Updated patch - small bug in suggestion when using overriden field template on view mode level

swentel’s picture

Status: Needs work » Fixed

This has been committed. Field template can be set on instance level as well.
In case there's another template, these are the suggestions (note, those of field.tpl are removed)

* field--minimal.tpl.php
* field--minimal--body.tpl.php
* field--minimal--article.tpl.php
* field--minimal--body--article.tpl.php

In case you want to add new theming functions, you can implement hook_ds_field_theme_functions_info(). Important is that theme_ds_field_ prefix is used so template suggestions work!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

zmove’s picture

Status: Closed (fixed) » Active

Reopen the issue because it seems that you don't have access to the $variable['ds-config'] informations in the field template.

For example I created a field--minimal.tpl.php to theme my fields, but I cannot get access to the "Hide colon" parameter to hide the colon if checked.

Did I miss something ?

Regards,

Alex

swentel’s picture

Title: Possibility to set field template on instance level + template file suggestion » Hide colon not accessible
Category: feature » bug
swentel’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Active » Closed (works as designed)

ok, I finally get it, this is actually working as designed, that variable is only available for expert field template.