How to reuse component on another page? | Community
Skip to main content
AppHaus
Level 2
September 20, 2017

How to reuse component on another page?

  • September 20, 2017
  • 5 replies
  • 5334 views

Hello

I have a component filled with the same data and would like to use it on other pages in the website.  How can this be done?  Rather than recreate this component over and over again 100 times and adding the same data 100 times. 

I tried copy but will not paste on another web page.

Thank you for your help!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

smacdonald2008
Level 10
September 20, 2017

Typically a component on a page has its own data that is separate from other instances of the same component on other pages. For example, if you have an image component - although its the same image component (same sling resource type) - each instance shows a  different image.

AppHaus
AppHausAuthor
Level 2
September 22, 2017

Then does Adobe have a query component to access a database or xml file?

smacdonald2008
Level 10
September 22, 2017

Adobe Provides the APIs to let you write your own component to access a database. For example, to access MySQL, you use a DataSourcePool and configure it. Then you can use it to query data from MySQL and display the data in a page. We have a developer artilce that shows you how to use the DataSourcePool API:

Scott's Digital Community: Injecting a DataSourcePool Service into an Adobe Experience Manager OSGi bundle

YOu can watch a video too.

kautuk_sahni
Community Manager
Community Manager
September 21, 2017
joerghoh
Adobe Employee
Adobe Employee
September 23, 2017

If you want to do content-reuse within a page, this should be carefully planned. There are a lot of different ways how you can achieve this, but each one has pro's and con's, and without knowing much more details about your usecase it doesn't make sense to go into details.

To name some ways to reuse content, let me list some from the top of my head:

  • iparsys
  • reference component
  • multisite manager (MSM)

The decision which one to use is driven by the (content) architecture of your application/site. From my point of view it should never be the decision of a developer which approach to use!

Jörg

AppHaus
AppHausAuthor
Level 2
September 27, 2017

I did not mark Jorg Hoh as the correct answer. 

The decision can be from a developer or designer!

joerghoh
Adobe Employee
Adobe Employee
September 28, 2017

Hi,

Of course a designer or a developer can make that decision, but in most cases a designer or a developer does not see all the consequences coming from that decision.

For example, are you aware of the consequences of using the MSM to achieve content reuse? It has impact on the authoring process as a whole, because authors now suddenly need to break inheritance to change a page. And enable inheritance to get the latest changes. If you use a kind of freestyle-MSM (neither planned nor managed usage of it) your authoring process will be unmanaged too, because noone understands easily what impact a rollout might have.

Then about the different rollout options, which will have a huge impact too. Not to talk about the resulting system load.

Same with iparsys or reference component.

Content reuse is an essential part of the information architecture and your business domain. I think that any decision and change here should made with care.

smacdonald2008
Level 10
September 28, 2017

We marked Joerg's answer as correct as he provided an excellent response that addresses this question.

AppHaus
AppHausAuthor
Level 2
September 27, 2017

So if you have a component like a -dropped down selector- listing all of the United States- for the user to choose from… you are basically stating here that it can't be done other than what I suggest is to created db or xml file.

Just wanted to be sure we are all on the same page here with my question.

Thanks again for your feedback!

joerghoh
Adobe Employee
Adobe Employee
September 29, 2017

Hi,

I appreciate your opinion and accept that you still want to pursue your approach. I am OK with that, because I still do not understand your situation completly. I tried to give you some ideas why I think your approach will cause problems, but it's okay that you won't accept it. No problem.

The easiest way to do it is likely the reference component. At each place you want to reuse the content add the reference component and point it to the original location. If you already have a component at the places, where the to-be-reused content has to appear and you cannot replace it, I don't think that there is a good solution available then. Then either you do a copy&paste approach or you write a small script (using whatever technology, e.g. shell using curl and the SlingPostServlet ) to automate it.

And to repeat myself: I think that the problem you just have is caused by a design issue.

Jörg

AppHaus
AppHausAuthor
Level 2
September 29, 2017

Regarding the reference component, this approach has been discussed and tested since we don't have control over the design as we would like.

Thank you for your time and contribution!