주 콘텐츠로 건너뛰기

Recipe: Add a link with some ticket data

Widgets에서
저자 리스트
발표됨: 2021년 11월 11일|최종 업데이트됨: 2021년 12월 13일

In this recipe we’re going to create a widget that shows a link in the ticket sidebar, with the link containg details of the ticket being viewed.

Firstly, create a new widget and under the “Description” tab, give the widget a title and description.

We don’t to define any settings, special permissions or proxy parameters. The only think we need to check is the "Ticket" target under the "Settings" tab.

Under the “Code” tab, in the “body” section add the following code:

<div class="container"> <div data-type="deskpro-template" id="link_template"> <a href="https://example.com/users/{{ data.ticket.primaryUser.email }}/view" target="_blank"> Example Email Link </a> </div> </div> <script> Deskpro.client.onShow(function (context) { Deskpro.utils.renderTemplate("link_template", context); }); </script>
copy

This example is slightly more complicated than the last. Here we need define a template which contains our link. Templates allow us to define placeholders for data that we may want to use in our HTML. In this case, we want to inject the primary ticket user's email address into the URL.

We natively support Handlebars templates, and we provide a utility that allows us to pass data to a handlebars template and render it to the page. Using the SHOW event, we pass the ticket context data to the template rendering utility like this:

Deskpro.client.onShow(function (context) { Deskpro.utils.renderTemplate("link_template", context); });
copy

Where link_template is the id of the template we'd like to render.

image.png

Ok, let's take a look at the widget in the Deskpro agent interface. Select any ticket and click on our newly created widget in the ticket sidebar and you should see the following:

image.png

Clicking or hovering over the link should reveal that the primary ticket user's email has been included in the link URL.

https://example.com/users/example.user@example.org/view
copy
도움이 되었습니다도움이 되지 않음
다음 페이지Recipe: API request that returns HTML
이전 페이지Recipe: Add a link

댓글을 작성하려면 로그인하거나 등록하셔야 합니다.