Allow users to share repeater content on social media

Farah El Agha asked on December 11, 2017 15:34

I have a repeater that shows the activities of an association, I want to include 2 buttons, one for Facebook and the other for Twitter and allow the user to share an activity on his account on social media. how can I do that with kentico?

Correct Answer

Brenden Kehren answered on December 12, 2017 09:19

You can use some code like this:

<div class="share-buttons-container">Share this via
  <a class="social share icon facebook" target="_blank" href="http://www.facebook.com/sharer.php
?u=<%# System.Uri.EscapeDataString(CurrentDocument.AbsoluteURL) %>
&p=<%# System.Uri.EscapeDataString(CurrentDocument.DocumentName) %>"></a>
  <a class="social share icon twitter" target="_blank" href="https://twitter.com/intent/tweet
?text=<%# System.Uri.EscapeDataString("Great Info: "+CurrentDocument.DocumentName) %>
&url=<%# System.Uri.EscapeDataString(CurrentDocument.AbsoluteURL) %>
"></a>
  <a class="social share icon pinterest" target="_blank" href="http://pinterest.com/pin/create/button/
?url=<%# System.Uri.EscapeDataString(CurrentDocument.AbsoluteURL) %>
&description=<%# System.Uri.EscapeDataString(CurrentDocument.DocumentName) %>
"></a>
  <a class="social share icon email" href="mailto:
?subject=<%# System.Uri.EscapeDataString("Look at this great info!")%>
&body=<%# System.Uri.EscapeDataString("I thought you'd like this: "+CurrentDocument.AbsoluteURL) %>"></a>
</div>

You can get what the URLs are from the respective social platforms developer documentation.

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on December 11, 2017 16:23

If it's a default repeater I guess you could create a custom user control that you reference in your transformation.

You could also create your own clone of the Repeater Web Part and use the databinding event to include some data.

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on December 11, 2017 16:30 (last edited on December 11, 2017 16:33)

David I am still kind of new to this, and this is the first time I include a social media share in my transformation, so can you please explain more about the process, or at least include an example? like if I wanna include a custom control in the transformation, what should be the code of this custom control?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on December 11, 2017 18:40

Some example with parameters:

http://asp.net-tutorials.com/user-controls/using/

In here you can include any custom logic you want.


If it's just outputting the same data you can also look into a custom Kentico Macro:

https://docs.kentico.com/k10/macro-expressions/extending-the-macro-engine/registering-custom-macro-methods

That just outputs a link to something like "https://twitter.com/intent/tweet?text=this is a tweet"

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on December 12, 2017 11:20 (last edited on December 12, 2017 11:23)

Thank you brenden, is it doable in macros? also does it affect the result if i have some document urls in arabic?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 12, 2017 17:34

It might be able to be done in macros but you need to call the System.Uri.EscapeDataString() method and right off hand I don't remember if there is a macro method for that or not.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.