Hi,
Just joined the group.
I have just started to use display suite and it's certainly saving me a bunch of time just setting teaser/full/custom view mode to a certain display, then I can re-use it with different content types.
Usually I'd hard code a load of stuff in each view using tokens and custom html to get the output I want.
One thing I can't seem to do is format the tags field. In views I can select that they will be inline, with a ',' or whatever as a separator.
How do I achieve this with display suite? I have used custom fields and can 'reset', 'minimal' etc, but that allows to change the html (so I can arrange them inline via css), but not to add a separator between the looped taxonomy terms on each node in my view i.e. in my teaser view mode...
I get as default:
Music
Videos
Pictures
Or with display suite I can get:
MusicVideosPictures
But what I want is:
Music, Videos, Pictures
One way I thought about doing it was to simply create a block in views that will be my taxonomy terms on the node with an argument for nid. Then add that block using display suite to the desired area in my teaser view mode. That would output the taxonomy terms in the way I want for each node teaser, however, I am wondering how others do this?
I hope this makes sense and someone can point me in the right direction.
Thanks.
Sam.
Comments
Aha, I stumbled across the
Aha, I stumbled across the answer quite by accident.
1) I added a dynamic field.
2) Edit content > chose 'Node'
3) Chose 'Node terms'
4) Node being viewed = yes, Vocabulary = category
5) TERM FORMATTING = inline,delimited
6) Link to terms = yes
7) Choose a delimiter, in my case a ','
8) Finish, update, profit!
Superb, I knew display suite could handle my requirements!
I hope this helps anyone else who wants to format their fields just that little bit more.
Sam.
Add this code to your template.php file
For D7: Add this code to your template.php file, substituting my references "o_thct" with the name of your theme.
This will work with your taxonomy terms, regardless of Display Suite.
Be sure to clear all caches -- at least theme registry after uploading the revised template.php file.
function o_thct_field__taxonomy_term_reference($variables) {
$output = '';
// Render the label, if it's not hidden.
if (!$variables['label_hidden']) {
$output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ': </div>';
}
// Render the items.
$output .= '<ul class="field-items"' . $variables['content_attributes'] . '>';
foreach ($variables['items'] as $delta => $item) {
// Set a delimiter
$delimiter = ', ';
// If the item is the last in the array remove the delimeter
if (end($variables['items']) === $item) {
$delimiter = '';
}
$classes = 'field-item-taxonomy ' . ($delta % 2 ? 'odd' : 'even');
// Output each taxonomy term item, with the delimiter on the end
$output .= '<li class="' . $classes . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . $delimiter . '</li>';
}
$output .= '</ul>';
// Render the top-level wrapper element.
$tag = $variables['label_hidden'] ? 'div' : 'section';
$output = "<$tag class=\"" . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . "</$tag>";
return $output;
}
Hi, Thanks. Is this just a
Hi,
Thanks. Is this just a way you do it or a preferred method?
I got it working with display suite using my method, but obviously, you then need to set up the custom field every time you use it in different view modes, which isn't ideal because it's the same whenever/wherever I use it on my small site.
How do I actually use your solution? Does it make a block? Never really delved into the programming side but keen to learn.
Sam.
How do I actually use your
How do I actually use your solution?
Exactly as I indicated.
It will automatically restructure the default listing of taxonomy terms as stacked items, and instead display them such as linear items seperated by comma.
Just try it. Save a backup of your current template.php file. Assuming that you are using a subtheme; if not, just try it and see if you like it. Then, you can do a proper subtheme where you would really apply the modification.
Excellent! Thanks. Now I get
Excellent! Thanks. Now I get it.
Sorry, one more, could this be achieved just the same using a display suite custom code field?
Sam.