Custom shortcodes to avoid hardcoding journal citation #131
-
I’m building an about page for our journal, and would like to include citation information for the journal as a whole avoiding hardcoding. ls it possible to create a shortcode to pull that information from the metadata? How difficult would it be to do this? I was hoping to implement something similar to the side-menu, which is a partial that pulls the citation info for each page from metadata files. Obviously, I cannot use partials with markdown pages, but am yet to figure out how I might do this with a shortcode. I have read the Hugo docs on shortcodes and partials, and searched GitHub, but hoped somebody might be able to point me in the right direction. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi Sophie, when you said:
You're absolutely correct that partials can't be used directly in Markdown pages, but the nice thing is that you can usually create a very simple shortcode that acts as a wrapper for an existing partial. If you had a shortcode called
You could then call it in the markdown, as: ## Citation Information
### Chicago
{{< q-cite-this type="chicago" range="site" >}}
### MLA
{{< q-cite-this type="mla" range="site" >}} ( That said, a HUGE CAVEAT, the cite-this partial is actually not all that robust and has not at this point been written with journals like Materia in mind. So, I think you're going to find that the resulting output is pretty wonky. Try it out though, and if you get the shortcode working, I'd be happy to work on the cite-this partial to see if we can fix the output. I'm sure it would be useful for other community members as well. I'd just need exact samples of what both the Chicago and MLA citations should ideally look like in your case. |
Beta Was this translation helpful? Give feedback.
Hi Sophie, when you said:
You're absolutely correct that partials can't be used directly in Markdown pages, but the nice thing is that you can usually create a very simple shortcode that acts as a wrapper for an existing partial.
If you had a shortcode called
q-cite-this.thml
with this code inside it:You could then call it in the markdown, as: