Going in circles with templates and shortcodes

Here’s the situation:

I am working on a hugo site that will drive a community-run event. Every city has their own event, and is responsible for creating their own additions. The structure we have built is that each city will have a datafile in the format of yyyy-cityname.yml. This contains a whole bunch of info that is used to list out things like sponsors, dates of the event, when the CFP’s are open and closed, etc.

The tricky part is getting each page to know which datafile to call in order to query and get its results (since every event has 9 pages, having to set these parameters in frontmatter is really a non-starter and not very DRY). I’ve created quite a few shortcodes for them to use in their content files (to return the start date, the twitter link, etc for the event).

Approach 1 - I added a parameter to every page called “event” which had the value of the name of the data file. This seemed really repetitive and prone to error, so I got rid of it when I discovered Approach 2 (below)

Approach 2 - I realized that I already has having everyone put “City” and “Year” in the frontmatter of each page, and since the datafile was composed of those two terms, it was easy to leverage them in the shortcode (since the shortcode seems to accept the .Params of the page on which it was called). This worked fine with my test event, which was “Chicago 2016”, but when I tried it with “Salt Lake City 2016” It obviously didn’t care for that :slightly_smiling:

Approach 3 - With some judicious use of split and .Source.File.Path, I thought I solved for this by creating the name of the data file on the fly. This works GREAT inside a template. It does NOT work inside a shortcode. I thought of passing the path to the shortcode, but of course since i’m doing that inside a content file, I can’t.

Any ideas?

Both 2 and 3 should work fine. In 3, try .Page.Source.File.Path. And to load data: .Page.Site.Data …

That did it! Approach 3 it is!

…it’s always a scoping problem… :slightly_smiling: