2

I have a block/view that shows teasers of the latest 3 articles.. This articles are full html, it contains layout (build with a WYSIWYG)..

On the homepage, I create a block that shows the latest 3 articles.. I can give it CSS-layout..

Block

But because it's build with the WYSIWYG, there are extra html-tags (span, a, p, ...) in the teaser, which can be different every time. The problem is that it overwrites the default layout for the teasers..

html of the teaser

I just want to keep the clean text on the frontpage block, and full-html on the detail page. How can I manage it?

Normally I should use strip_tags(); in PHP to remove html.. But how can I do it only for that specific block?

2

Add the body field and trim it.

enter image description here

Now in your web directory, go to /sites/all/themes/yourtheme/ folder and in template.php add the following code:

function yourtheme_preprocess_views_view_fields($vars){

  if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1") {
    $vars['fields']['body']->content = strip_tags($vars['fields']['body']->content);
  }

}
  • replace yourtheme with the actual name of your theme
  • replace view_name with the name of your view.
  • replace block_1 with the machine name of your view. If yours happens to be block_1 then leave it the same.

In Drupal, clear/flush your cache to see the changes.

Then add the other fields you want on your view, title, post date? comment link? etc... basically you create your own teaser.

PS: You can add classes to your fields, if you need to use css on them.

| improve this answer | |
  • I'm trying this.. So far so good.. But like you said, it ends stripping everything.. Now trying part 2. – Finduilas Jul 8 '16 at 10:48
  • I used the whole solution, it works like a charm! I use classes, but inline css overwrites it always ;-). Thnx! – Finduilas Jul 8 '16 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.