The theming capabilities currently implemented in CCK are excellent, however, theming needs to be extended to allow themers greater flexibility. Some parts of CCK are very easy to theme. It is very simple to theme how raw CCK data is taken from an array and merged with HTML for output. The “display fields” menu gives themes a solid set of preset output settings. If these presets fall short, themers can create field-specific templates in the cck/templates folder. This is where CCK’s theming is strong. However, theming becomes much more difficult after the CCK data is merged with HTML.

Problems

  • Themers cannot easily control the order of CCK fields and the body text in $content. CCK allows the re-ordering of fields for the input field. CCK should have a output weight option to control the order of elements in final output.
  • Content_format can be used to get the HTML output of each individual element. However, it bypasses any field templates associated with it. In addition, it makes the “display menu” useless, since themers must set CCK fields to hidden in order to use content_format (otherwise fields will appear twice). In addition, it can often be difficult to get the name of the specific presets, especially for new themers.

Contemplate does solve the problems above, however, it is far from practical. Themers have to manually take data from the array and output html in the template. This is very impractical especially since modules already have theme functions that are made to process the data for specific fields. Contemplate supersedes theme functions that may fit themers needs, but themers are forced to use contemplate to reorder CCK fields on output.

Possible solutions

  • In the “display menu” provide an option that does not place the CCK field in $content and puts the final HTML output of the field (using cck/templates and supporting multiple field values without a foreach as content_format requires) in the $node array so it can easily be printed out. This way themers can use the simple “display menu” options (i.e. raw text, trimmed, imagecache presets, etc) and retain layout flexibility. Another alternative would be to create a function that is given a field name and data, and returns the entire results (not just 1 field in the case of multiple field values).
  • Include weight in the display menu, allowing themers to reorder elements.
  • Although not mentioned as a specific problem, it would be helpful is themers could specify CCK field specific templates for a particular theme. For example, the cck/templates folder applies to all themes. If a CCK template could also be placed in a theme folder, than, a particular theme could overwrite CCK output.

These solutions would increase the flexibility of CCK for themers. My understanding and experience in CCK is far from exhaustive. If CCK already includes options or alternatives to these problems I would greatly appreciate direction on how to solve the issues listed above.

Comments

yched’s picture

Status: Active » Fixed

However, theming becomes much more difficult after the CCK data is merged with HTML.

This is a general shortcoming in current drupal node rendering mechanism, true for any module that adds to nodes. CCK is only one of the most widely used...

In short : true, it's either print $content, or use detailed code, but then you cannot use $content and have to handle the whole node by yourself.
Known problem, not specific to CCK. See #134478: Refactor page (and node) rendering.

CCK allows the re-ordering of fields for the input field. CCK should have a output weight option to control the order of elements in final output.

It does. The ordering of fields on the 'Manage fields' tab applies to node form *and* node display. Agreed, this is a limitation, and it would be nice to have per-context ordering (node forms, full node, teaser, etc...). A good UI for that is far from trivial, though.

In the “display menu” provide an option that does not place the CCK field in $content ...

Sorry, that won't happen.

... and puts the final HTML output of the field (using cck/templates and supporting multiple field values without a foreach as content_format requires) in the $node array

Agreed, this is needed. Duplicate request of #294797: 'full field' variable in node.tpl.php. Let's deal with that over there.

Although not mentioned as a specific problem, it would be helpful is themers could specify CCK field specific templates for a particular theme. For example, the cck/templates folder applies to all themes. If a CCK template could also be placed in a theme folder, than, a particular theme could overwrite CCK output.

That's how it works already. Changing the contents of modules/cck/theme is actually bad practice, your templates need to be in your theme's folder.

yched’s picture

In the “display menu” provide an option that does not place the CCK field in $content ...

Sorry, that won't happen.

Well, that was a bit radical.
I've been thinking about this, might come up with something. Probably not in the 'Display Fields' UI, though, because the need for this depends on what your theme's node templates need to do, so this would need to change theme per theme.

yched’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

michaelfavia’s picture

Perhaps progress on this issue was made on another front but I have implemented a module that assigns a weight to the fields during hook_nodeapi($op = view). This allows me to move the fields around without using theming and still relys on the standard output templates. Would adding an AHAH table sorter to the content type display settings (like manage has) and alter the order if present be a welcome patch in d6? I can write it this week if so.