Update
You should probably just use the Global Custom Text fields method described here. No need to apply any patches to use that method.


This patch adds support for "prefix" and "suffix" markup per field in the Semantic Views row style settings.
This allows me to take for instance 4 fields:

<img />
<h2></h2>
<p></p>
<a></a>

and wrap some of them in a div:

<img />
<div>
  <h2></h2>
  <p></p>
  <a></a>
</div>

That is accomplished by setting a prefix of "<div>" on the <h2> field and a suffix of "</div>" on the <a> field.

Now, this does mean you're entering freeform HTML and so it's up to you to make sure you don't break your markup structure.

This seemed the simplest way to implement this feature but I'd sure love if Semantic Views had a nice table-drag-and-drop hierarchical control that lets you add wrapper tags and put your fields "under" them. That'd probably be the more "right" way to accomplish this feature.

@bangpound: Thoughts?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

I've quickly reviewed the patch. I think you've done everything correctly.

The risk here is that the field whose suffix you rely on to close the prefix tag of another field-- this field could be excluded. Semantic Views can't stop you from writing bad HTML, but I think this may be one that is too easy to get wrong.

Did you try to use Global Custom fields with token rewrites?

However, I need to think about this some more.

adamdicarlo’s picture

I think it would be easier to get it wrong when using Global Custom Text fields because you have to click through separate fields in the views interface...whereas this shows all the prefixes/suffixes at once.

adamdicarlo’s picture

@bangpound, any ideas on how to make this patch acceptable for semanticviews?

I'm not sure it's actually possible to (e.g.) wrap a group of fields in a div with standard views tricks (I tried it with global custom text fields, and it was a world of broken markup hurt no matter what I did)....

Anonymous’s picture

Status: Needs work » Needs review

Sorry to delay Adam.

The balance I'm trying to strike with Semantic Views is to fulfill all of the possibilities of the Views field row style (which offers interchangeable HTML elements, but only span and div) and add crucial functionality to simplify theming where it costs very little to do so.

I have needed to wrap fields in a container before, and so far the only reliable solution is to override the template.

I think this introduces some strange UI problems. Prefixes and suffixes are not the right way to think about markup containers/wrappers.

Anonymous’s picture

Status: Needs review » Needs work
jhedstrom’s picture

Status: Needs review » Needs work

I have used this patch successfully on several projects now. Views itself, and Drupal core commonly use #prefix and #suffix for container/wrapper divs, so as far as the end result, I think it is on track.

The UI is a bit funky, but I still drastically prefer a more confusing UI at this level than having to create and maintain a separate template file (which isn't theme agnostic).

jhedstrom’s picture

FileSize
2.69 KB

Here's the same patch, but rolled with --no-prefix and --relative so it applies cleanly when using drush_make.

mavimo’s picture

Assigned: Unassigned » mavimo
Category: feature » task
Status: Needs work » Needs review
FileSize
72.69 KB
7.15 KB

What it do

This patch generate a configurable fields wrapping functionality for fields in each rows.

How to use

Into attachment you can see fields interface where you can configure your wrapper for fields.

Fields without wrapper don't change, other are wrapped from "Wrapper" element with "Wrapper class". If more then one element have the same "Wrapper" and "Wrapper class" this fields are aggregate from then same wrapper.

Configuration into screenshot generate this output:

<ul class="test">
  <li class="views-field-tid"><!-- FIELD --></li>
  <li class="views-field-image-path"><!-- FIELD --></li>
  <li class="views-field-created"><!-- FIELD --></li>
</ul>
<span class="views-field-title"><!-- FIELD --></span>
<div class="views-field-occhiello"><!-- FIELD --></div>
<div class="another-test">
  <div class="views-field-comment-count"><!-- FIELD --></div>
  <div class="views-field-view-node"><!-- FIELD --></div>
</div>

Let me know if you found some bug or require some improvement.

mavimo’s picture

Fixed wrong order for element without wrapper and wrapper element.

dcronk’s picture

I've applied the patch, but it's only printing the wrapper without the wrapper class. I'm using Semantic Views 6.x-1.1 and a Zen 2.0 subtheme. Anyone else experience this?

mavimo’s picture

@wingzinco: can you send me (use pastebin :P ) a demo views with this error? Thanks!

dcronk’s picture

@mavimo - Sure, here it is: http://drupal.pastebin.com/eMsLShfD

I have a class set on each wrapper element, but it doesn't seem to be printed in the view.

Thanks.

dcronk’s picture

Any further thoughts on this? I'm using jQuery to wrap a div around a group of content, but there is the delay of waiting for the DOM to load before my styles are applied. If this could be solved with this patch, it would be a huge benefit. Thanks again for anyone willing to help.

mavimo’s picture

@wingzinco: this patch solve your problem (views generated page and block).

mavimo’s picture

#10 & #12 fixed.

adamdicarlo’s picture

I think the "use the same tag and class setting per row for grouping" is a little unintuitive but overall the new version of the patch is (I hope) a lot likelier to be accepted into the project, and it does the job -- admittedly, the extra flexibility of prefixes and suffixes is overkill for most all uses...

@bangpound, thoughts about mavimo's new version of the patch?

mavimo’s picture

@adamdicarlo: I'm agre with you but using tag-class combination is the simple and powerfull solution I found. I also think to create a wrapper elements are fields and configure it, but is more complex and not really fast (it don't work on theming layer but in query layer with a lot of possible problem on performance).

arski’s picture

Hey there,

this is a nice patch, but I have to say it's very limited.. it would be nice if someone were able to create something more generic, where you could really create multiple level wrappers for any fields, so you might want to have an image left and a content area right, and then several sections inside that content area etc..

But anyway, kudos for this and just as a note - this is something I could use on basically any site, so it's a really great thing to have.

Cheers,
Martin

mavimo’s picture

@arski: I'm agree with you, but add sub-wrapper can increase UI complexity, and I don't know how to "manage" this functionality (UI side), but if you propose a mockup i can try to implement code to make it possible :)

Sub-wrapper also reduce "the Semantic" of element, but this is just a "sub-issue" :P

arski’s picture

you're right, it's not easy UI wise. Off the top of my head I would create something similar to how Fieldsets work in CCK. So basically have a new field type like "Field group" and then when you go into the interface where you can move view fields up and down, have the option of moving them inside a field group as well..

To be honest I don't think this can be done in the semantic views interface, but it should be doable in the default views interface in the fields section.. or?

mavimo’s picture

@arski: is not possible add this functionality into Semantic Views, SV interact into theming functionality of views, field is data-related and is not "correct" insert theming functionality into it, but is also possible create a similar interface into SV settings, I'm try to "immaaginate" this interface and how to set that on options.. not simple, but not impossible :)

shp’s picture

The balance I'm trying to strike with Semantic Views is to fulfill all of the possibilities of the Views field row style (which offers interchangeable HTML elements, but only span and div) and add crucial functionality to simplify theming where it costs very little to do so.

Ok, implement the simple but powerful feature - editing the row/view templates from the UI.

P.S. I had the same task (wrapping of semantic-views fields), but I've used Global Custom fields with HTML-markup parts. There are no problems with that solution.

sunshinee’s picture

Title: Thumbs up on this matey! » Patch: Allow wrapping groups of fields in tags (prefix and suffix per field)

I haven't reviewed this patch, but regularly use Semantic Views and have run into the same need. My quick-and-dirty solution is to exclude and rewrite the fields, adding tags as needed.

For example:
*****************************
Field-1: exclude from display
Field-2: exclude from display
Field-3: exclude from display

Field-4: rewrite output to include fields 1-4 (you can use HTML here if needed), then give Field-4 the div element using Semantic Views to wrap them all inside.
*****************************

This probably isn't the best solution, but I thought I'd post in case it helps someone who needs to wrap fields while the patch is being evaluated.

adamdicarlo’s picture

I'm still using my original patch (as rerolled by jhedstrom in #7) -- it's served well through several site builds now.

stevehuk’s picture

There seem to be two proposed approaches here. Perhaps Bagpound could comment on whether either of these is likely to be included in Semantic Views. This would give early adopters using a patch a view on which one would minimise the need for rework later.

Being able to group some fields in a wrapper is something I need. Whilst the global custom fields approach works, it seems messy since it makes view changing more difficult and creates another place where CSS is kept. Something built into Semantic Views would be really good. In principal either of these could functionally do the job.

rolfmeijer’s picture

subscribe

monotaga’s picture

Has there been any more thoughts on this? Has anyone explored if there's support for this in Views 3 since it has elements of Semantic Views incorporated?

mavimo’s picture

@monotaga: I'm working on a solution for having wrapped fields with D7 and V3, update into next weeks.

kmadel’s picture

You could use Views along with Display Suite. Display Suite allows you to add custom fieldgroups that can be displayed as a div element with whatever classes you would like to apply.

drupal a11y’s picture

Could you also provide this for the D7 version? I would love it!

cameron prince’s picture

I was looking for a way to do this and ran across this issue. When I saw there was no D7 version, I started playing around with another solution. It seems, at least with D7, that you don't need extra modules or patches to do this.

My need was to put a product image on the left side and then list product details on the right. What I ended up doing was to create 3 global text fields. The fields are laid out as follows:

1) First a global text field with its contents set to: <div class="product"><div class="product-image">

2) Then I display my image as normal.

3) Then another global text field with contents of: </div><div class="product-details">

4) Then I list all my detail fields.

5) Finally a third global text field containing: </div></div>

The key is to make sure Customize field HTML, Customize label HTML and Customize field and label wrapper HTML are checked under STYLE SETTINGS in each global text field. All three of these should have a value of -None- in the element selector. All Create a CSS class and the Add default classes should be unchecked.

tkiddle’s picture

Title: Patch: Allow wrapping groups of fields in tags (prefix and suffix per field) » Thumbs up on this matey!

Fantastic thanks for that... great tip! I'll be using that a lot for sure.

adamdicarlo’s picture

Wow, I was pretty surprised to see "Thumbs up on this matey!" in my followed issues block :P

Also, this issue should probably be closed with won't fix or works as designed since the "Global custom" method is simpler and works in D7 too.

Anonymous’s picture

I'm concerned that this is overwrought. At some point, you need to be willing to edit a template. It also looks easy to create prefix and suffix values that will completely wreck your output. In other words, it feels like a very advanced feature that would be used correctly by people who hopefully understand how to edit templates.

However, I'm looking for someone to take over maintenance of this module. If you're willing, you could commit this patch. I've read the patch, and the code looks fine.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

Scyther’s picture

Version: 6.x-1.1 » 8.x-2.x-dev
Category: Task » Feature request
Issue summary: View changes
Status: Needs review » Active

I use panels and a custom panel to achive this. Or and is comment #23 is a way to also solve it.

Moving to 8.x-2.x and keeping it active to see if this is needed in never version.

Leagnus’s picture

cameronbprince, your solution (#31) is brilliant!

demonde’s picture

I noticed that Semantic Views is incompatible with Views fieldsets.

Should I open a feature request about this incompatibility? Or is it by design impossible and should be solved like the patch in this thread?