I'm pretty new to functions and PHP (so please forgive my terminology) but here's what I would like to do:
Background
My homepage contains a view displaying various content type teasers. I would like to truncate the title of an article teaser (a custom teaser created with display suite) to 48 characters.
Action taken so far
If I add the following code to my subtheme's template.php file, nothing happens:
function THEMENAME_preprocess_node(&$variables) {
if ($variables['type'] == 'article' && $variables['view_mode'] == 'teaser') {
$variables['title'] = truncate_utf8($variables['title'], 48, TRUE, TRUE);
}
}
However, if I add this other variation of the code (i.e. applying to all teasers, not just article teasers) the titles of some teasers are indeed shortened:
function eunic_global_preprocess_node(&$variables) {
if ($variables['teaser']) {
$variables['title'] = truncate_utf8($variables['title'], 48, TRUE, TRUE);
}
}
Conclusion & Question
I think the problem is to do with the fact that some teasers have been created using the Display Suite module while others use more or less the default teaser.
So my question is - how do I 'refer' to the title of a teaser made with display suite in order to apply the truncate_utf8 function? Fingers crossed there's a way to do it...
Thanks A~
sites/all/modules/ds/layouts/ds_1col/ds-1col--node.tpl.php
. However, I don't know how to override the template - the file makes no specific references totitle
only to$ds_content
and$ds_content_wrapper
. Would you have any further suggestions? Thanks again.