Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Update Page Properties with component data

Avatar

Avatar
Coach
Employee
jbrar
Employee

Likes

387 likes

Total Posts

869 posts

Correct Reply

283 solutions
Top badges earned
Coach
Establish
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Coach
Employee
jbrar
Employee

Likes

387 likes

Total Posts

869 posts

Correct Reply

283 solutions
Top badges earned
Coach
Establish
Give Back 50
Give Back 5
Give Back 3
View profile
jbrar
Employee

10-05-2019

Is it possible to take information entered into a component field, and have it put into fields within the page properties?

We’d like to have a component where the page author could enter a title and description and have the values overwrite the page title and the page description as found in the page properties dialog.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

11-05-2019

Hi,

Please, don't overwrite page properties with properties from a specific component (by whatever means). Instead you should write your title component in a way, that it can display the correct value by reading it from that specific sub-component. In that case I would explicitly build logic into the title component Sling model, which looks for another component on that page and reads the correct title from there (preferably using the model class of that component instead of directly reading from the repo).

In general, I consider this not a good pattern. Because the title of the page is defined at a page level, and not on a component level. You should rethink if your properties are located at the right components.

HTH

Answers (4)

Answers (4)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

10-05-2019

Hi,

You can use dialog value to update page property by writing a listener of dialog.

As soon as you submit the dialog, make a ajax call to the sling servlet or sling post servlet like curl with properties and update the nodes.

Below are the example/way how to do it, They are not the working code.

e.g. 1 Sling custom servlet

(function ($, $document) {

  "use strict";

  $(document).on("click", ".cq-dialog-submit", function (e) {

var dialogprop = $('#filedId');

var page = Granite.author.pageInfoHelper.json.status.path

$.post('/bin/utils/updatepage', { field: dialogprop, path : page},

    function(returnedData){

         console.log(returnedData);

});

  });

})($, $(document));

e.g. 2 sling post servlet

(function ($, $document) {

  "use strict";

  $(document).on("click", ".cq-dialog-submit", function (e) {

var dialogprop = $('#filedId');

var page = Granite.author.pageInfoHelper.json.status.path

$.post('page', { "jcr:title": dialogprop},

    function(returnedData){

         console.log(returnedData);

});

  });

})($, $(document));

Avatar

Avatar
Validate 1
Level 1
alexandriths
Level 1

Like

1 like

Total Posts

2 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
alexandriths
Level 1

Like

1 like

Total Posts

2 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
alexandriths
Level 1

10-05-2019

Yes, it is possible, but I'm not sure if a component would be the best way to perform this task.

For example, in order to write the custom code for updating the page properties, you would most likely create a Java Sling Model for the component.

In this Sling Model, you could get the current page, check if the title matches the value mapped from the configuration of the component, and if they don't match, update the page properties.

The reason why you likely wouldn't want to do this with a component is because that Sling Model will do that check every time it is rendered on a page, and you would basically only want to run that check once since it would just be an update that occurs once when the component is authored or edited.

Not sure what your exact use case is, but editing the page properties to have a different title isn't that difficult from an authoring standpoint, and I don't really see the ability of being able to update the page title via a component creating a better authoring experience.

Perhaps training your authors on to how to easily update the page properties to have a different title might be a better route than having to do a custom implementation on a component.

Hope this helps.

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

12-05-2019

Agree with Joerg.

Please use page properties in component but not vice versa.

Avatar

Avatar
Validate 10
Level 3
ankurk67503819
Level 3

Likes

15 likes

Total Posts

89 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 10
Boost 5
Boost 3
View profile

Avatar
Validate 10
Level 3
ankurk67503819
Level 3

Likes

15 likes

Total Posts

89 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 10
Boost 5
Boost 3
View profile
ankurk67503819
Level 3

10-05-2019

You can write custom code to iterate over your page node and update the pageproperties once you update your component dialog.