Hi all

I've been using Drupal (7) for the past three years now. On the whole I really like it - nothing else comes close in terms of raw power and extendibility. HOWEVER... I have a question that I have not yet been able to answer in a satisfactory way.

Imagine we have a page (node) and on this page I would like some additional fields. Perhaps just one sentence, or a statistic, or an image. In WordPress, this is simple - you can add custom fields to any post or page and render them in a template without any fuss whatsoever. In Drupal, this is not easy. The following options come to mind:

Use a block
You could use a block, but I really don't like that the site editor would need to locate and edit a block instead of being able to do it all in one place.

Use Node Field (module)
I tried this module but it was a massive pain to work with - printing the fields in a template was so much hassle.

Create a content type for this page (with fields)
Seems very wasteful and not sustainable.

As a site builder, I want the CMS to simply handle my content in a flexible fashion. For me this has been the biggest issue with Drupal so far. So the question is - how would you go about tackling this seemingly simple request?

Thanks,
Matt

Comments

Anonymous’s picture

This sounds like the sort of thing Paragraphs might help with:

https://www.drupal.org/project/paragraphs

webbymatt’s picture

Thanks Steve, I have actually taken a look at that. Are the fields accessible to the .tpl? This is the most important thing for me, and where Drupal fails compared to WP. I simply want to do something like:

<h2><?php print $content['field_name']; ?></h2>

Having Drupal simply print the output (no style or anything).

Thanks!

Anonymous’s picture

Try Drupal 8. Doesn't sound like you're doing anything core can't do and it's in RC now so won't be long before it's 'official'!

willhallonline’s picture

Hey,

Just to add onto Steve's comments, we have been using Paragraphs for about a year and a half (after using Panels extensively for about 4 years), and we normally offer both on clients sites. They nice addition about paragraphs is that we normally pre-load sites with multiple paragraph options (1 column, 2 column text, 2 column image/text, 3 column etc) and they people have far more control over exactly where they want content.

This has the advantages that content writes can control some of the presentation without actually having to write any code and the site administrators can limit the permissions of different content editors as required. Basically you theme your paragraphs as separate entities and then render them inside the nodes. We did a blog post about it relatively recently (not trying to blow our own trumpet) http://www.willhallonline.co.uk/blog/non-techie-friendly-drupal-paragrap... and some of the other stuff we normally put in http://www.willhallonline.co.uk/blog/will-hall-onlines-drupal-starter-kit.

Hopefully it helps.

webbymatt’s picture

Thanks for this, I'm going to have another look at Paragraphs on a clean install I think, see how I can fit it in with future builds.

@Steve - I tried D8 a couple of months ago, now it's at release stage I'm going to give it another run. Just need to find the time!

Thanks guys

danharper’s picture

It totally depends on the context of what you are doing.

If you want an image on a node then you need to add an image field or if you need a piece of text then you need to add a text field. Does that not fit the use case?

Dan

webbymatt’s picture

How can I add an image field to a node though? Even by using Paragraphs, fields are added to Content Types, not individual nodes.

Anonymous’s picture

A content type provides the definition, you don't have to add an image to each 'node' you create. So you can add an image field to a 'story' content type no probs.

webbymatt’s picture

I know we've had this out on Twitter but just for the sake of clarity on here... a content type provides a function for adding repeating content. What I'm talking about is a single piece of content. I understand this can be achieved by using a block, but as stated previously it's very inelegant as the editor will need to locate the block on the blocks page, when really I want everything to be editable on the same page. A semi-solution would be to link to the block edit page on the node edit page but still, it's messy.

What I want is the ability that WordPress has using Custom Fields, where every piece of content (i.e. every node) can have it's own fields.

medenfield’s picture

Check out panels and panelizer. You can 'panelize' an individual node, then add custom content to a region, and place it where you want within your chosen panels template.

Greg Boggs’s picture

Hi Matt,

I often work in both WordPress and Drupal and I think we're a bit off track in this discussion. In WordPress, when you add a field to a post or a post type, you then need to write some custom code and then manually print it in a tpl file and add custom logic in your theme. This works, but it doesn't scale and it's not flexible. It creates code that isn't particularly easy to maintain. For a large project like Nasa.gov, for example, it requires you to make a massive number of custom PHP templates. But, it's great if you just need to print a one off string on a blog post.

In Drupal, you do the same thing by creating a content type and adding a text field to that content type in the UI. You can use this to print a field on a single node, but that's an extremely rare use case in websites. Contrary to your thought that this action not sustainable, it's actually very sustainable because it gives you a system to print the field when you need and reuse it in many places as you need to.

It's *GREAT* that WordPress has custom post types, custom page types, and custom fields now. But, it's not nearly as mature, flexible, and easy to use as Drupal's content type UI. This isn't to say WordPress isn't great. WordPress performance and scalability blows Drupal 8 out of the water.

~Greg