templates.Defer in content adapter

So I understand defer is disabled on content adapter because “No, that would not make sense.” but I’m currently trying to fix some thing that would definitely benefit from that.

I have some pages divided by “souce”, but I need to combine all of them in new pages automatically. What I’m doing is adding the pages to the global store on render:

{{- if eq .Type "mytype" -}}
  {{- site.Store.SetInMap .Type .Path . -}}
{{- end -}}

And then using that store in the content adapter:

{{ range $path, $page := site.Store.Get "mytype" }}
  {{ $.AddPage ... }}
{{ end }}

To be clear, it works in the dev server if I re-trigger the content adapters after all pages render, but of course it fails in the normal build.

I’m looking to contribute this change, but I’m not sure if there is interest or how hard it would be to implement.

I’ve read this a few times, and I don’t understand either the starting point or the objective. Can you please clarify (a) what you have, and (b) what you want.

I have some pages like this:

/books/my-book/collection/my-collection (.Type = collection)
/books/my-book/element/my-element-1 (.Type = element, .Params.collection = my-collection)
/books/my-book/element/my-element-2 (.Type = element, .Params.collection = my-collection)
/books/another-book/element/another-element (.Type = element, .Params.collection = my-collection)

I want to render those pages in their location but also:

/collections/my-collection
/elements/my-element-1
/elements/my-element-2
/elements/another-element

I can achieve it with aliases, sure, but in the /collections/my-collection page I want to display a table with all the matching elements (type element with the matching collection field) as well.

Hope it helps.

Do you really need to publish pages in two locations, or is this just a matter of building a page collection?

Having two different pages would make sense for me since then you can see which stuff comes from my-book and which comes another-book.

I guess what I really want are resources rather than actual pages that I can compose as I please. But it would create issues for the content inside the books that isn’t a collection or an element, if that makes sense.

I still don’t fully understand your goal, but…

  1. You don’t need a content adapter
  2. Publishing a page to more than one URL isn’t a great idea
  3. It seems like you might want re-usable content, probably using one of the GetPage methods

Yes I could organize the content in another way, I understand, but I want to abstract as much as possible the content from the “site” logic and I’m not sure how it can be achieved with what you’re suggesting. In the end what I’m considering is using the sources as an asset and creating as many pages as I want in a content adapter.

It makes sense here. You should be able to browse book by book or “globally”.

What I’m looking for here is a “double-hugo” approach, where I can use the section/page tree of a site to build another site.