0

Require a little help with removing the pre-parsed text from Dukt's {{ twitterTweetButton() }}

 <li><a href="  {{ twitterTweetButton({
                        text: "some text",
                        target: "_blank"
                    }) }}"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>

This does not work....

The docs specify the following Twig functions:

  • text — Pre-populated text highlighted in the Tweet composer.
  • url — URL included with the Tweet.
  • hashtags — A comma-separated list of hashtags to be appended to default Tweet text.
  • via — Attribute the source of a Tweet to a Twitter username.
  • related — A comma-separated list of accounts related to the content of the shared URI.
  • size — Set to large to display a larger button.
  • lang — A supported Twitter language code. Loads text components in the specified language. Note: does not affect the text of the cited Tweet.
  • dnt — When set to true, the Tweet and its embedded page do not influence Twitter targeting including suggested accounts.
Nutmeg
  • 598
  • 1
  • 4
  • 17

1 Answers1

1

This is what the function currently does

public function tweetButton($options = [])
{
    $dataAttributes = $this->getOptionsAsDataAttributes($options);

    $html = '<a class="twitter-share-button" href="https://twitter.com/share"'.$dataAttributes.'>Tweet</a>';

    return $html;
}

So it returns an a tag rather than a link. You should remove your outer tag but you can't place your custom text. You would have to use a string replace function

{{ twitterTweetButton()|replace({'>Tweet<':' >my custom text<' }) }} 
Robin Schambach
  • 19,713
  • 1
  • 19
  • 44
  • Thanks Robin, what I am trying to figure out is how to use these Twig functions (see above). The example I used to change the text for example, however I didn't get any results. PS: the string replacement doesn't work either... – Nutmeg Apr 18 '18 at 23:55
  • Like I said, this won't do anything because the function does not work the way you want. As you can see there is no way to change the text. It's a hard coded string. You need to use the replace filter – Robin Schambach Apr 18 '18 at 23:57
  • The plugin's manual tells otherwise, thats all, however these instructions are related to Dukt's Craft 2 version. (see above) Thanks for your help, Robin. – Nutmeg Apr 19 '18 at 00:08
  • Do you want to remove the "Tweet" string from the button or the text in the field? However it will still return a html element and no link – Robin Schambach Apr 19 '18 at 04:46
  • Thank you, Robin - I don't want to waste more of your time. I've dropped all Dukt's plugins and am working on a custom solution.. – Nutmeg Apr 19 '18 at 08:09