How to mimic usage of shortcode in page template?

Hi,

In my site, I have a section for hiking trips. In this section, all the pages are a bundle of a thumbnail, a GPX file, a couple of coordinates and a index.md. I then have a section template in order to render these information by including a leaflet map.

This solution works, but I have to maintain the leaflet related code. :tired_face: And nowadays I dsicovered projects like GitHub - okainov/hugo-leaflet and Martin Rubli / hugo-mod-leaflet · GitLab . :star_struck:

But these projects provides shortcodes. So, I’m unable to reuse these shortcode in my page template. And, of course, I don’t want to replace my template with a copy-paste-hell by including the shortcodes directly in the index.md.

Is there a hack to call these shortcode?
Is there a change I can suggest to the upstream projects in order to allow me to reuse their features in my own template? For example, I read a shortcode can call a partial: should I suggest to create many partials?

Thanks in advance for any idea.

Not a direct answer, but… I add whatever I need for a map as JSON strings in data-… attributes to the div container for the map and then use JS to create the map from these values.

Simplified

<div class="destination-map" 
data-cities="[&quot;Managua&quot;,&quot;San Rafael del Sur&quot;,&quot;Léon&quot;]" 
data-imgs="[&quot;blog/blick-zur%C3%BCck/presseausweis-1980-150.webp&quot;,&quot;/blog/san-rafael-del-sur-schulen-wasser-gesundheit/blick-in-den-vulkankrater-150.webp&quot;,&quot;/blog/nicaragua-f%C3%BCr-touristen-stadt-und-land/wandbild-in-leon-150.webp&quot;,]" 
data-locations="[[12.1459907,-86.2746665],[11.846482,-86.4388639],[12.4345376,-86.8773498]]" >

The JS code then creates a marker for each data-location point with an image and a URL. For your application, you’d probably need an array of GPX points to draw a line with leaflet.

Not saying that this is the best way, it just suits me. The projects you pointed to use shortcodes embedded in shortcodes, I don’t see that easily converted to normal templates.

To be honest, I don’t quite understand what the problem is…
You have a section where each page has coordinates and a GPX file,
and a section page that gathers all the hacking points to create a map.

It seems perfectly logical to me that each page in this section would have fields like latitude, longitude, and gpxfile. That way, you can display the map both on the section page and on the individual location page. Why do you even need shortcodes for this?

Unless you just find it convenient to show the map on the location page exactly where you want it. I definitely don’t understand; maybe an example would make it clearer. Could you please show me exactly what you need?

I read a shortcode can call a partial

That’s the way I usually go. The shortcode is nothing but a short wrapper to call a partial with just the same set of parameters. This also has the advantage that the underlying partial can not only be called from any other partial but also from a code block render hook.

Mermaid example shortcode implementation, codeblock renderer, partial implementation, shortcode doc (the partial API is a user feature and therefore documented).

In times of AI agents, the task to switch existing code to such a structure, should be really simple and straight forward. In case the maintainer does not have AI access, it is still relatively simple (obviously based on the maintainer’s own capabilities) but becomes tedious pretty quickly :wink: