HUGO

Copy Section from another one via shortcode

Hi,

I would like to copy specific title from one content to another one via shortcode. What I mean, ı’ve some contents where we are using the same one with different contents or md files.

For instance, let assume I’ve two different md files… I am using Lorem Ipsum with paragraph in another md.file… Can I copy this specific section to another md file via shortcode ?

first.md

title: "Lorem "
linkTitle: "Lorem Ipsum"
weight: 1
description: >

---

Lorem Ipsum --> here is the title and section that ı would like to copy with paragraph

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy

Lorem

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy

second.md

title: "Lorem "
linkTitle: "Lorem Ipsum"
weight: 1
description: >

---

Shortcode here
<< copy content … >>

Regards,
Semih

Are you talking about copying/cut’n’pasting content inside of one single page or between different pages?

Copying and reusing things inside a page is done via Scratches. It’s a bit more complicated:

Between two pages I see a way with GetPage if you know what content you need:

I would like to copy and paste the specific part inside one content to another contents… What I mean, let assume that I 've Header A and Paragraph A inside content/docs/test1/_index.md… I need to copy only Header A and Paragraph A to another content lets say content/docs/test2/_index.md.

Thus when I change something the rest of them are also affected.

I still can’t wrap my head around it, maybe someone else can help, because you are describing a very abstract problem.

Let’s use a real-life example and you tell me what you need different from this:

  • you have a file in a folder content/sitewide/authorprofile.md
  • you want the content of that file turn up on all pages in the footer or sidebar or right after the title

That is possible by using .GetPage in a partial or shortcode.

Or

  • you want to have content particles that you can add at arbitrary locations (like “contact me blabla” with a nice form inline where ever you want it)

That too I would create with a separate content file that is loaded via shortcode in the resulting content file.

Both my examples separates the content you want to re-use (and reuse is the only thing that I understand from your requirements) from the other contents it is used in (as in physically in different folders). There surely is some kind of hierarchy or file structure that is separating the “from” content file from the “to” content files.

Feel free to explain with apples and pears, easy language :wink: