Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Twitter Widget Pack Problem


Reply


1051 Views

Avatar
ambient

Community Member, 123 Posts

5 August 2011 at 4:01am

Edited: 05/08/2011 5:18am

------------UPDATE----------------

Nevermind, I just ended up taking the twitter widget from here [url]https://twitter.com/about/resources/widgets/widget_profile[/url] and passing variables directly into it and it works fine :)

Hi all,

I've been trying to get the Twitter feed on my website using the Twitter Widget Pack.

I've taken the code from the TwitterProfileWidget.php and TwitterProfileWidget.ss files and transferred them to my respective Homepage files but the area for the twitter feed comes up blank.

When I look at the source code it shows some of the variables passed properly but the defaults like height and width are still null.

Can someone tell me am I missing something really obvious??

Homepage.ss

<div class="twitter_box"><!--start twitter_box-->
   <script src="http://widgets.twimg.com/j/2/widget.js" type="text/javascript"></script>
   <script type="text/javascript">new TWTR.Widget($WidgetSetupJSON).render().setUser('$User').start();</script>
</div>
<!--end twitter_box-->

Source Code

<div class="twitter_box"><!--start twitter_box-->

<script src="http://widgets.twimg.com/j/2/widget.js" type="text/javascript"></script>

<script type="text/javascript">new TWTR.Widget({"version":null,"type":null,"rpp":"2","interval":"0","width":"0","height":null,"theme":{"shell":{"background":"black","color":"white"},"tweets":{"background":"black","color":"white","links":"white"}},"features":{"scrollbar":true,"loop":true,"live":false,"hashtags":false,"timestamp":true,"avatars":true,"behavior":"default"}}).render().setUser('@twitter').start();</script>

</div>
<!--end twitter_box-->

Homepage.php - Snippets

public static $db = array(
   
   //Twitter
   'TwitterUser' => 'Varchar(20)',
      'TweetCount' => 'Int',
      'TweetInterval' => 'Int',
      'SizeHeight' => 'Int',
      'SizeWidth' => 'Int',
      'SizeWidthAuto' => 'Boolean',      
      'ShellBackground' => 'Varchar(7)',
      'ShellColor' => 'Varchar(7)',
      'TweetBackground' => 'Varchar(7)',
      'TweetColor' => 'Varchar(7)',
      'LinkColor' => 'Varchar(7)',
      'FeatureScrollbars' => 'Boolean',
      'FeatureLoop' => 'Boolean',
      'FeatureLive' => 'Boolean',
      'FeatureHashtags' => 'Boolean',
      'FeatureTimestamp' => 'Boolean',
      'FeatureAvatars' => 'Boolean',
      'FeatureBehavior' => "Enum('default, all', 'default')",
   //Twitter
   );
-------------------------------------------------------------
static $defaults = array(
      'TweetCount' => 4,
      'TweetInterval' => 10000,
      'SizeHeight' => 300,
      'SizeWidth' => 250,
      'SizeWidthAuto' => true,
      'ShellBackground' => '#333333',
      'ShellColor' => '#ffffff',
      'TweetBackground' => '#000000',
      'TweetColor' => '#ffffff',
      'LinkColor' => '#4AED05',
      'FeatureScrollbars' => false,
      'FeatureLoop' => false,
      'FeatureLive' => false,
      'FeatureHashtags' => true,
      'FeatureTimestamp' => true,
      'FeatureAvatars' => false,
      'FeatureBehavior' => 'default',
   );
---------------------------------------------------------------
$fields->addFieldToTab('Root.Content.Twitter', new TextField('TwitterUser', 'Account Name'));
   $fields->addFieldToTab('Root.Content.Twitter', new DropdownField('TweetCount', 'Number of Tweets', range(1, 20)));
   $fields->addFieldToTab('Root.Content.Twitter', new NumericField('SizeHeight', 'Height (px)'));
   $fields->addFieldToTab('Root.Content.Twitter', new TextField('ShellBackground', 'UI Background Color'));
   $fields->addFieldToTab('Root.Content.Twitter', new TextField('ShellColor', 'UI Text Color'));
   $fields->addFieldToTab('Root.Content.Twitter', new TextField('TweetBackground', 'Tweet Background Color'));
   $fields->addFieldToTab('Root.Content.Twitter', new TextField('TweetColor', 'Tweet Background Color'));
   $fields->addFieldToTab('Root.Content.Twitter', new TextField('LinkColor', 'Link Color'));
   $fields->addFieldToTab('Root.Content.Twitter', new CheckboxField('FeatureScrollbars', 'Display Scrollbars'));
   $fields->addFieldToTab('Root.Content.Twitter', new CheckboxField('FeatureLoop', 'Loop Results'));
   $fields->addFieldToTab('Root.Content.Twitter', new CheckboxField('FeatureHashtags', 'Display Hashtags'));
   $fields->addFieldToTab('Root.Content.Twitter', new CheckboxField('FeatureTimestamp', 'Display Timestamp'));
   $fields->addFieldToTab('Root.Content.Twitter', new CheckboxField('FeatureAvatars', 'Display Avatars'));

return $fields;
}
function User() {
      return Convert::raw2js($this->TwitterUser);
   }

   protected function WidgetSetup() {
      return array(
         'version' => $this->version,
         'type' => $this->type,
         'rpp' => $this->TweetCount,
         'interval' => $this->TweetInterval,
         'width' => ($this->SizeWidthAuto ? 'auto' : $this->SizeWidth),
         'height' => $this->Height,
         'theme' => array(
            'shell' => array(
               'background' => $this->ShellBackground,
               'color' => $this->ShellColor,
            ),
            'tweets' => array(
               'background' => $this->TweetBackground,
               'color' => $this->TweetColor,
               'links' => $this->LinkColor,
            )
         ),
         'features' => array(
            'scrollbar' => ($this->FeatureScrollbars ? true : false),
            'loop' => ($this->FeatureLoop ? true : false),
            'live' => ($this->FeatureLive ? true : false),
            'hashtags' => ($this->FeatureHashTags ? true : false),
            'timestamp' => ($this->FeatureTimestamp ? true : false),
            'avatars' => ($this->FeatureAvatars ? true : false),
            'behavior' => $this->FeatureBehavior,
         )
      );
   }

   function WidgetSetupJSON() {
      $settings = $this->WidgetSetup();
      return Convert::raw2json($settings);
   }