Search code examples
apostrophe-cms

Display apostrophe-widget in apostrophe-page


I have:

  • 3d extending apostrophe-pieces
  • 3d-pages extending apostrophe-pieces-pages and
  • 3d-widgets extending apostrophe-widgets

My 3d-widgets/views/widget.html is correctly displaying a 3D object.

How can I use that widget when displaying a 3d object with 3d-pages/views/show.html?

I do not want to reinvent the wheel and copy 3d-widgets/views/widget.html to 3d-pages/views/show.html.


Solution

  • You want both your show.html and your widget.html to make use of a nunjucks macro so that you have an isolated bit of markup that's sole job is to render 3d objects.

    You can see that pattern illustrated in the Open Museum when rendering cards that display information about a specific artist.

    Here is the macro we will use in other components to render the card. It is just a function that accepts arguments and returns markup. https://github.com/apostrophecms/apostrophe-open-museum/blob/master/views/macros/artist-cards.html

    Here is the artist index page where we iterate over pieces and render cards using the macro https://github.com/apostrophecms/apostrophe-open-museum/blob/f1756c566e46f85f6370a3d1a2c934b342dc7478/lib/modules/artists-pages/views/index.html

    And then the Search results page also makes us of the macro to display information about artists returned as part of a search https://github.com/apostrophecms/apostrophe-open-museum/blob/b2b20a4d7da355c8f448a1442dd17b4a76c2f285/lib/modules/apostrophe-search/views/index.html#L5