Set thumbnail for a page using javascript api


(Arivarasan) #1

Matrix Version:

Hi, i want to assign thumbnail to the page using java-script API through front-end ,
i want to run onclick function in frontebd so that thumbnail automatically assign according to asset id of the page .
please anyone can help ?
Thanks


(Anthony Ponomarenko) #2

Hey there,

There is a similar question and solution here - Set thumbnail in Javascript

Does this help you at all?


(Arivarasan) #3

Hi,
yes, i have seen this before i wan to run javascript function . i have tried the solution on Set thumbnail in Javascript but i found no result/

Thanks


(Bart Banda) #4

You would need to use the setAttribute JS API function
https://matrix.squiz.net/manuals/web-services/chapters/javascript-api#setAttribute

Have a look at that. You will basically set an asset ID of the thumbnail asset as the thumbnail attribute.

You can also use https://matrix.squiz.net/manuals/web-services/chapters/javascript-api#getAttributes first to find out what the attribute value is called, but I think it’s just “thumbnail”


(Arivarasan) #5

Hi Bart ,
Thanks , i will check it .


(Arivarasan) #6

Hi,
I try to set attribute but getting following error :-
[“Attribute “thumbnail” does not exist for Asset “luke-skywalker-test” (#10499)”]
i have also get the attribute for page but did not get any attribute for set the thumbnail .
Thanks


(Arivarasan) #7

here is my code
js_api.setAttribute
(
{
asset_id: 10499,
attr_name:“thumbnail”,
attr_val:10504,
dataCallback: function(data)
{
alert(JSON.stringify(data));
}
}
)


(Bart Banda) #8

Ah, my bad. I think you actually need to use the createLink function.
https://matrix.squiz.net/manuals/web-services/chapters/javascript-api#createLink

Set the Thumbnail asset as a NOTICE child link to the asset you want to use it as a thumbnail for, with link value thumbnail.


(Peter McLeod) #9

Hi

As Bart said try this:

js_api.createLink({
           "parent_id": id_of_asset_to_add_thumbnail_to,
           "child_id": id_of_thumbnail_image,
           "link_type":8,
           "link_value":"thumbnail",
           "sort_order":1,
           "is_dependant":0,
           "is_exclusive":0,
           "dataCallback":callBackFunction
  });

Also check your JS API is set to allow links to be created, and that the scope of the JS API covers all assets involved.
Thanks
Peter


(Arivarasan) #10

Hi PeterM,
Thanks for reply. I did the same and it work for me .
Thanks