0

I want to show a list of links to the 5 latest news on my homepage.

I learned that I can install the Views module to make a snapshot of a content type. I also use EVA to create a EVA field from the view and attach it to my homepage content type.

Then I can intercept the value of the view in my homepage_preprocess_node but the problem is that the value is a long string containing the whole list wrapped with html.

This is bad...

I want to have full control of the html. I tried different options but couldn't find a clean, basic, barebone option.

I am expecting a value that is an array of 5 objects so I can loop throught them and generate what ever html I see fit. The object would contain the field I asked (title) and a url to get to the news page.

Of course I can remove the html tags and rebuild the array from that long string but I don't want to do that if there is a better solution. I will use that view on the "press room" page also, so I don't want to have to duplicate code in two different preprocess_node functions

Nothing is simple in Drupal...

I wanted to add "EVA" as a tag for this question but it's not available.

0

That's because you are doing it the hard way. Why hardcoding everything when views does it out of the box? Views fields are extremely flexible and customizable. You may need to strip the views fields first (style fields and deselect whatever option you have - do that also with your format / html, unformatted etc). Usually, what I do is exclude from display and use views tokens in the last field of type Global text area. This way, the view only displays actually field values, with no html whatsoever.

To escape hard coding even for your content type display, try using display suite. It works smoothly with EVA as well.

I hope I got it right.

And... what is simple when you're trying to achieve complex structures? Is there any other platform delivering something like views OOTB?

There is some research to be done regardless choice of environment. And usually, the shortest, simplest way, is the way you know better.

  • I disabled the maximum options regarding html and the simplest form I got was a string with <div><a href="...">title</a></div> for each entry. I want an object that I can manipulate in my template file not a string. (similar to the content type's field) – Guillaume Bois Mar 31 '15 at 19:23

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.