Model.json | Community
Skip to main content
Level 2
November 9, 2024

Model.json

  • November 9, 2024
  • 2 replies
  • 807 views

I want my custom page properties to include in the json.model ootb page 

How can I do that?


I already create a new field in dialog , and try to expose them but still don't works. 

 

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;

@Model(
    adaptables = SlingHttpServletRequest.class,
    adapters = ComponentExporter.class,
    defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
    resourceType = "core/wcm/components/page/v3/page"
)
@Exporter(
    name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
    extensions = ExporterConstants.SLING_MODEL_EXTENSION
)
public class ContentPageModel implements ComponentExporter  {

  static final String RESOURCE_TYPE = "core/wcm/components/page/v3/page";
  // Custom properties
  @ValueMapValue
  private String pageTitleContentPage;

  @ValueMapValue
  private String pageDescription;

  @ValueMapValue
  private String titleTag;

  @ValueMapValue
  private String date;

  public String getPageTitleContentPage() {
    return pageTitleContentPage;
  }

  public String getPageDescription() {
    return pageDescription;
  }

  public String getTitleTag() {
    return titleTag;
  }

  public void setPageTitleContentPage(String pageTitleContentPage) {
    this.pageTitleContentPage = pageTitleContentPage;
  }

  public void setPageDescription(String pageDescription) {
    this.pageDescription = pageDescription;
  }

  public void setTitleTag(String titleTag) {
    this.titleTag = titleTag;
  }

  public void setDate(String date) {
    this.date = date;
  }

  public String getDate() {
    return date;
  }

  @Override
  public String getExportedType() {
    return "core/wcm/components/page/v3/page";
  }
}

My Expectation is it included in here

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

2 replies

joerghoh
Adobe Employee
Adobe Employee
November 10, 2024

It seems that you want to override the exporter for the v3 page template of the Core Components. And most likely there is already one for it, and for that reason it's not working.

 

I would recommend that you define for your own pages a dedicated resourcetype (you can define the v3 page as supertype) and use it. And then you can define your own sling model for it.

Fendy_Author
Level 2
November 11, 2024

I'm already try using my own resource type , but now the json only show this it don't show the OOTB exporter , do you know how can I solve this issue ?

So I also want to include the ootb exporter

 

arunpatidar
Community Advisor
Community Advisor
November 11, 2024

HI @fendy_ 
Can you share the sling Model for how did you extend the new page component with v3/page?

 

Arun Patidar
kautuk_sahni
Community Manager
Community Manager
November 11, 2024

@fendy_ Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni