Expand my Community achievements bar.

SOLVED

Dynamic header title component issue with multiple websites on the same platform

Avatar

Level 3

HI I'm using AEM 6.3 Editable templates.

I have created a custom Template A.

Site1,Site2,Site3,Site4 are built using Template A and I have header title component on each site which should be unique per site, PFB screenshots for the reference.

we need help to build this title component dynamic for multiple websites, so that the title is dynamically picking from the title of the root page.

1664471_pastedImage_6.png

1664473_pastedImage_7.png

1 Accepted Solution

Avatar

Correct answer by
Level 1

You could use context aware configuration to define the title once and then render it in all pages ( only required if the structure differs between projects).

Apache Sling :: Apache Sling Context-Aware Configuration

View solution in original post

4 Replies

Avatar

Correct answer by
Level 1

You could use context aware configuration to define the title once and then render it in all pages ( only required if the structure differs between projects).

Apache Sling :: Apache Sling Context-Aware Configuration

Avatar

Level 10

Team replied:

Seems like the simpler approach is to just manage it as structure title component – I cant imagine the site name changes often.

If core componets don’t support this- you’d need a new component.

Avatar

Level 3

Hi Tim,

I have implemented dynamic title component using Context Aware Configuration.

I have followed Jörg Hoh​  blog Sling Context-Aware configuration (part 2) | Things on a content management system

1.Is there any way to automate the creating nodes on conf location?

2.same way i have implemented dynamic navigation component in editable templates, here i am facing issue.

It is always taking default path.Navigation component not taking latest page path. I can see latest path in my in my logs.

Here is my code

1.NavigationRootCAConfig.java

@Configuration(label = "Navigation Root Context Aware Config")

public @interface NavigationRootCAConfig {

   @Property(label = "Navigation Root")

  String navigationRoot() default "/content/site1/en";

}

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

public class LeftNav {

   protected final Logger logger = LoggerFactory.getLogger(LeftNav.class);

   private String DEFAULT_NAV_ROOT = "/content/site1/en";

   private List<Page> navItems = new ArrayList<>();

   private Page currentPage;

   private String navigationRoot;

   @Inject
  @Optional
   private boolean collectAllPages;

   @Inject
  @Optional
   private int structureDepth;

   @Self
  @Via("resource")

  Resource resource;

   @SlingObject
   ResourceResolver resourceResolver;

   @Inject
   ComponentService componentService;

   @PostConstruct
   protected void init() {

   logger.info("Nav Root Path : " + navigationRoot);

   logger.info("Collect All Pages : " + collectAllPages);

   logger.info("Structure Depth : " + structureDepth);

   if (StringUtils.isBlank(navigationRoot)) {

   navigationRoot = getNavigationRoot();

   logger.info("Navigation root {} .....", navigationRoot);

   navItems.addAll(componentService.getNavItems(navigationRoot, collectAllPages, structureDepth));

  }

  }

   public List<Page> getNavItems() {

   return navItems;

  }

   public String getNavigationRoot() {

   currentPage = resourceResolver.adaptTo(PageManager.class).getContainingPage(resource);

  String path = currentPage != null ? currentPage.getPath() : "";

   if (!StringUtils.isBlank(path) && resource != null) {

   NavigationRootCAConfig navRootCAConfig = resource.adaptTo(ConfigurationBuilder.class).as(NavigationRootCAConfig.class);

   logger.info("Navigation root path {} *** ", navRootCAConfig.navigationRoot());

   navigationRoot = navRootCAConfig.navigationRoot();

  } else {

   navigationRoot = DEFAULT_NAV_ROOT;

  }

   return navigationRoot;

  }

   public void setNavigationRoot(String navigationRoot) {

   this.navigationRoot = navigationRoot;

  }

   public boolean isCollectAllPages() {

   return collectAllPages;

  }

   public void setCollectAllPages(boolean collectAllPages) {

   this.collectAllPages = collectAllPages;

  }

   public int getStructureDepth() {

   return structureDepth;

  }

   public void setStructureDepth(int structureDepth) {

   this.structureDepth = structureDepth;

  }

   public Page getCurrentPage() {

   return componentService.getCurrentPage(navigationRoot, collectAllPages, structureDepth);

  }

   public void setCurrentPage(Page currentPage) {

   this.currentPage = currentPage;

  }

   public void setNavItems(List<Page> navItems) {

   this.navItems = navItems;

  }

Can anyone help here?

Thanks,

Kiran

Avatar

Employee Advisor

Please open a new thread for this question; this thread has been marked as answered, thus it's less likely that people are looking into this post. I would not have checked this thread if you had not pinged me directly :-)

Regarding to your question: you can package and deploy them. But as these values are supposed to change during runtime you should not include it into regular deployment. And one of the most relevant aspects is that it should be optional. If authors decide to change some default value, they will create the new value in /conf (e.g using the CA configuration editor).