Content Blocks Export Options

Does anyone know if there’s a good way to export the Content Blocks fields along with resource fields and TVs. I’ve written a Snippet to export them but the best I could do is create unique column names for a lot of the fields but it seems to assign numbers (I think might be iterations of the field). I just want to have the content available to migrate to a new site.

It’s invariable that people will need or want to redesign their website as time passes and business changes. I’m not sure how people are doing this without resorting to a lot of copy and paste.

Personally, I’d only recommend such page builders for resources that might not have structured content. For products, people, news, blogs etc, those should all be structured content objects—even if just using TVs.

Any help or guidance on an approach to get the content and image references into columns for a content migration would be welcome.

/cc @markh

There are import/export options built into the component for the field definitions themselves. The content is stored in the resource properties column but I think you found those already.

The numbers you’re referring to are probably the field IDs? Bit hard to tell without seeing what your snippet generates and pulls from, and to some extent how the site in question was built, but the field keys in the properties json refer to the IDs.

Iterating over elements is what the field and layout definitions are for; as long as you have those structured in a meaningful way you can edit those and rebuild the content to update the generated markup. Mileage may vary depending on how a site is built tho.

Along this thread, I’m curious if there’s any way to take portions of a content block resource and move it to another resource. I have one page that is getting very long that really needs to be 4 different pages and I’d rather not have to redo all the content blocks from scratch. What I’m looking for is a content and field export. I’m sure that’s not doable, but since this is the topic here I figured I’d ask.

And yes, I am also considering putting the content into resources so they can continue to add content without having to build anything with a content block.

Its not really clear for me what you both want to do, but i want to share some ideas that come in my head when reading this (:

I use Gitify to transfer content between sites. Extract the resources and ContentBlocks fields. See my .gitify file: MODX-Gitify-Preset/.gitify at 8e60225b7c63e53c588c40c91fc69499cb8ea15d · jenswittmann/MODX-Gitify-Preset · GitHub

When you want to split a ressource in multiple resources, maybe duplicate the ressource four times and delete whats not needed?

This is also interesting when you want to use an existing content as template: MODX Content Blocks: turn a layout on a resource in to a template.

2 Likes

In this case, I only want to split the resource into a few other resources. The duplicate and delete is likely the easiest way forward with this. I’ve used the content block templates on another site and the client is actually dependent on them in an almost unhealthy way, ha! They work for their purposes, with several nested layouts that make things do their stuff. This site is simple, and just needs to organize itself. Thank you for the idea and links!

Doesn’t Content Blocks just keep all its setup stuff in the Properties field in the database, and create a fully rendered HTML version in the regular Content field? That’s what it looks like to me. Of course you’d have to render an TV tags inside the content if you’re not duplicating the TVs in the new setup. If someone needs the content for a new site that doesn’t use Content Blocks, why do you need the Content Blocks info at all?

I’m looking to keep structured content types that have been put into content blocks fields together. I want to be able to pull that out but not necessarily pull out the combined HTML output of all the CB fields in one pile.

The challenge is that the structured content should not have been put into Content Blocks originally, IMO. It was done this way because CB was there, but it ended up getting used for everything. I think Content Blocks is perfect for helping build out whole pages, such as marketing landing pages. For things like products, articles, case studies, or other easily defined content objects, I feel those should use either TVs or a custom Resource type or separate tables. This offers much more ability to incorporate the structured content fields into things like API endpoints, rich content, meta fields, and more.

I’d love more folks to consider whether or not the content should be designed for export, reuse, or partial reuse and decoupled from the output format. In this situation, there are several hundred pages that will require a significant amount of copy and paste. I’m hoping to reduce the amount of said copy and paste for this site rebuild as much as possible.

@jenswittmann @jenswittmann The use case for me is a rebuild of the site, so the content design and output will not be a 1:1, and we’ll be putting products and articles into well-defined fields via TVs and possibly a custom Resource types. We will incorporate some page building for some of the landing pages, but for products, I don’t want to be stuck like this again. It’s possible that at some point in the future, the site will be rebuilt, and I’d like to ensure that it’s a simple content migration at that time.

1 Like

Is the structured content in one repeater field, or is it built with multiple fields/layouts? If it is in one repeater field, you can loop through the resources and retrieve all the fields using the cbGetFieldContent snippet with the &returnAsJSON option. This will give you the same structure to parse and use for import.

Jay, I’m looking at this same possibility with one of my clients, but their content is very possibly going to remain as is, or if anything I’ll rebuild the content blocks for a different display. The content is a lot of RTE and other standard elements and they really like to design their own pages and layouts. I definitely have always wanted to be able to export the content, but so far have not needed to. The other site where I need to right now is easily solved with duplicate pages, but this other one could be tricky like you’re dealing with.

@markh have you considered making this possible? Ideally I’d be able to grab a whole layout or the entire content area with any number of layouts to pop into another resource. My client wanted to do that, but I have them duplicating resources and editing them. I’m pretty sure I’m the only one who can build a nested layout for the resources they use on repeat. So duplication is their best option really. And then it can be a lot of copy and paste depending on what they’re trying to do. Even I get confused trying to use the content blocks and layouts that I created for this site sometimes if it’s been a hot minute since I messed with the site.

The roadmap for ContentBlocks2 (which you can find on the modmore website) includes the ability to copy elements (blocks or entire layouts) and paste them somewhere else, including different pages. That would make your use case @frogabog easier to move, but don’t ask me when that’s going to be production ready.

I do agree with Jay’s sentiment that things like product info ideally shouldn’t be inside of CB, because while you can use cbGetFieldContent to get there, that’s very easy for an editor to break and just having it somewhere like a TV or Commerce makes that much more solid and future proof.

1 Like

I offered the client TV’s long ago, and they have enough differences for their products that it wasn’t worth automation. And honestly, they really love designing their own pages and accordion tabs, and several other custom pages that they use regularly and want to just make happen. They have embraced content blocks for this purpose. If I could do TVs for their content, I would. It is not all repeatable and CB filled a need.