Default component content in template components | Community
Skip to main content
trench999
Level 4
October 16, 2015
Solved

Default component content in template components

  • October 16, 2015
  • 9 replies
  • 7583 views
<div class="text" > <cq:include path="bodytext" resourceType="foundation/components/text"/> </div>
 

I am embedding foundation components in a page component (see the following) and need to set some default content.   How do I go about this?

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

Use the page template. Add the components that you want to be on the page below the /app/myapp/templates/mypagetemplate/jcr:content node, and also add the content to the components.

See the page template of the geometrixx-outdoors sample: /apps/geometrixx-outdoors/templates/page/jcr:content/par/title

Edit; Here is another way to do it, which might be easier for authoring the content: http://dev.day.com/docs/en/cq/current/developing/boilerplates.html

hope that helps,
scott

9 replies

Scott_Brodersen
Scott_BrodersenAccepted solution
Level 8
October 16, 2015

Use the page template. Add the components that you want to be on the page below the /app/myapp/templates/mypagetemplate/jcr:content node, and also add the content to the components.

See the page template of the geometrixx-outdoors sample: /apps/geometrixx-outdoors/templates/page/jcr:content/par/title

Edit; Here is another way to do it, which might be easier for authoring the content: http://dev.day.com/docs/en/cq/current/developing/boilerplates.html

hope that helps,
scott

smacdonald2008
Level 10
October 16, 2015

Can you please elaborate on what you are trying to do. Are you asking how to set default components on a page. You can configure the page to use paragraph system and then an author can drag and drop components from the side kick to a page. 

<%@include file="/libs/foundation/global.jsp" %>
<cq:include script="/libs/wcm/core/components/init/init.jsp"/>
<html>
<head>
<title>AEM Twitter Feed Page</title>
</head>
<body>
<h2>This page displays twitter feeds</h2>
<cq:include path="par" resourceType="foundation/components/parsys" />
</body>
</html>
trench999
trench999Author
Level 4
October 16, 2015

Thanks, Scott.  This is not directly related to what I want to do, but I had not seen the boiler plate option before.  I can push default components on page as you suggest or directly embedded in the template jsp.  The issue is adding default content for a given cq:include.  It would be best to have an attribute that allows direct injection of the placeholder text and even better we would have a reference attribute that could pull content from a /content node.  Where do we add such requests?

trench999
trench999Author
Level 4
October 16, 2015

No, I am doing this with the snippet above.  I am trying to setup "placeholder" or default text on the text component I have setup already on the page.

Scott_Brodersen
Level 8
October 16, 2015

Ah ok I think I misunderstood your original question (sorry). I'm not sure you can do that in a good way without a custom component because the jcr node for the component needs to be created before you can add the content. (please, somebody correct me if I'm wrong)

If you know the location of the node that is created (approximately) you could use a workflow and a launcher to inject the content after the node is created

http://dev.day.com/docs/en/cq/current/workflows/wf-using.html#Starting%20Workflows%20When%20Nodes%20Change

 

scott

smacdonald2008
Level 10
October 16, 2015

Just extend the text component and set the default text. All components in CQ can be extended. For information, see:

http://dev.day.com/docs/en/cq/current/developing/widgets.html

trench999
trench999Author
Level 4
October 16, 2015

No worries.  

It was seem like if you had some content or a reference in a cq:include tag then that would server as a parameter in the instantiation of the component instance.  

eg.

<cq:include path="bodytext" resourceType="foundation/components/text"/ placeHolder="/content/placeholder-1">
trench999
trench999Author
Level 4
October 16, 2015

Thanks, but we should not have to extend a component every time we want some default text.  This is is not conducive to author experience.  What other alternatives are there?

smacdonald2008
Level 10
October 16, 2015

You can either extend the component or modify the text component itself. However, modifying the text component is not really recommended. Its better practice to make a copy, modify the copy (set the default text) and use that. See this topic "DEVELOPING A NEW COMPONENT BY ADAPTING AN EXISTING COMPONENT"

located here:

http://dev.day.com/docs/en/cq/current/getting_started/first_steps_for_developers.html

Once you create the new component, you can add it to the sidekick. An author would drag it from the sidekick and then see the default text. An author would never create a component -- this is a developer task.