There are a whole lot of variables available in the .tpl.php file, and explicitly printing each (as is the case now) makes the template file pretty messy.

I don't know if it is possible, but it would be nice if both the logic and the number of necessary PHP variables to print could be reduced by moving some processing to the semantic_cck_preprocess_content_field function.

Just a thought. :-)

Comments

rjay’s picture

Status: Active » Postponed (maintainer needs more info)

I agree that logic should always be placed in a preprocess function, and I believe we've done that as much as possible in Semantic CCK. The current contents of the semantic content field .tpl are essentially the same as the normal field content field .tpl, with hard-coded div/label tags replaced by variables.

The only other logic we've added is if statements to determine if variables are empty or not before printing them, which I believe is acceptable in a template file. Reducing the number of if statements is probably the only modification I'd attempt to make.

Did you have any suggestions as to what specifically you would move to the semantic field preprocess function? I'm willing to consider modifications to the semantic content field .tpl as long as we don't restrict the amount of freedom themers have if they choose to override it.

Ryan

itangalo’s picture

Hm, I see your point. There really aren't that many places where the code could be shortened.

However, here is one suggestion:

  <?php if ($label_display == 'above') : ?>
    <<?php print $label_element; ?> class="field-label"><?php print t($label) ?><?php print $label_suffix; ?></<?php print $label_element; ?>>
  <?php endif;?>

could be changed to just if ($label_display == 'above') : print $label; if the $label variable is set to conatain all of the variables and markup above. (The individual elements could still be available in the tpl.php if anyone would like to use them explicitly.)

It becomes more tricky with the inline labels, since they could be repeated for multiple-value fields. *Maybe* $label could be used as an array, with one value per field instance. But I don't know what consequences that might have when preparing the variable.
If it is too complex to use a $label variable for multiple-value fields, it doesn't really make sense to use it for labels above the field. So maybe this whole issue is more or less pointless. :-/

I'll give it some more thought, and if I come up with something smart I'll write a line or two.

Cheers!

rjay’s picture

Title: Lessen number of variables in the template file » Optimize code in the semantic field template file
Assigned: Unassigned » rjay
Category: feature » task
Status: Postponed (maintainer needs more info) » Active
rjay’s picture

Status: Active » Fixed

I've reduced the amount of whitespace in the template file and used the drupal_attributes() function on the field label to reduce the amount of logic in the template file a bit. These changes are committed and are included in version 6.x-1.4.

Status: Fixed » Closed (fixed)

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