1

I'm trying to create a Matrix field containing plain text blocks of two kinds, one for providing Youtube video embed codes, and one for providing a description. What I want to know is, is there a way to make it so users can add another field of either kind if they want to embed another video and/or provide another description, or do I have to "build" each field option in manually?

For example, the less elegant way I tried to solved this problem involved creating multiple fields, but since the handles all have to be different, I tacked a number onto each (mainYoutubeEmbed, youtubeEmbed2, youtubeEmbed3, and etc.) This just seems so clumsy and is completely non-DRY. The other option I considered to make it slightly better was to create a bunch of generic fields all with the same title and handle (so I could just loop through them), but Craft says that the handles must be unique.

Is there any way around this or a way to make it at least a little better, or is the best approach really to just create a bunch of fields and hope that my users don't need more in the future? Maybe a plug-in or magic incantation of some kind?? :)

PS. I know the titles can be the same, but I changed them to match the handles because if I find that I'm stuck with this janky method, I want it to be as easy as possible to "see" how it's laid-out.

Thank you in advance for all constructive advice.

enter image description here

1 Answer 1

2

I might get you wrong but they must have the option to add as many youtube embed videos as they want?

Isn't it an option to let your client make a new block for every embed and just loop over the blocks they made?

So your block would look like:

Youtube Video (block)

  • Youtube embed link
  • Youtube Description

So they just have to add a block when they want a new one and you can just loop over them like you would with any matrixblock?

3
  • Yes, that does sound like what I WANT to do with this, but I'm just not seeing a way to do that in the dashboard-- Glad my question at least sounds sensible... It would be great to just make one generic field for the embed and description in the block and let the user add additional fields with that same type/handle as needed... I'm hoping I've just overlooked this functionality somewhere and that it's not just a "would be nice" situation........
    – scoffin
    Commented Mar 6, 2017 at 15:55
  • Why would you use it for the dashboard? If you add the matrix to a page they can keep adding videos or How do you mean on the dashboard? Commented Mar 6, 2017 at 16:36
  • 1
    Meh... It looks like I jumped the gun and it is an option right from the dashboard... It was my first Matrix field so I think I just misunderstood how they worked... Womp womp. Thank you for responding, @Justin Dekkers!
    – scoffin
    Commented Mar 6, 2017 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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