base
(Arivarasan)
November 25, 2016, 12:54pm
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
Pono
(Anthony Ponomarenko)
November 27, 2016, 11:37pm
2
Hey there,
There is a similar question and solution here - Set thumbnail in Javascript
Does this help you at all?
base
(Arivarasan)
November 28, 2016, 8:25am
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
(Bart Banda)
November 28, 2016, 9:47am
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”
base
(Arivarasan)
November 28, 2016, 9:58am
5
Hi Bart ,
Thanks , i will check it .
base
(Arivarasan)
November 28, 2016, 12:17pm
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
base
(Arivarasan)
November 28, 2016, 12:18pm
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
(Bart Banda)
November 28, 2016, 10:00pm
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.
1 Like
PeterM
(Peter McLeod)
November 28, 2016, 10:33pm
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
4 Likes
base
(Arivarasan)
November 29, 2016, 8:26am
10
Hi PeterM,
Thanks for reply. I did the same and it work for me .
Thanks