variable data in Twitter Timeline username and password |
|||
|---|---|---|---|
| Date: | 03/16/2010 | Show-stopper?: | |
| Status: | See Comments | Reporter: | TPE |
| Reported in Version: | 2.0.1PB 20100215 | Assigned To: | Greg Aker |
| Keywords: | Add-On Issues, Plugins, | ||
| Support Thread: | |||
Details
I wanted to introduce variable data in the form of a text input custom field as the username and password for Twitter Timeline, every effort resulted in the same error returned when the username and/or password is incorrect or unset (with type set to user).
as a call to a text input custom field-
{exp:twitter_timeline type="user" user="{exp:channel:entries channel="site-wide_ch" disable="categories|member_data" limit="1"}{twitter-username}{/exp:channel:entries}" password="{exp:channel:entries channel="site-wide_ch" disable="categories|member_data" limit="1"}{twitter-password}{/exp:channel:entries}" limit="3"}
a snippet (containing the channel entries tag)-
{exp:twitter_timeline type="user" user="{twitter_username}" password="{twitter_password}" limit="3"}
a php variable set to the snippet’s value-
<?php
$tuser = {twitter_username};
$tpass = {twitter_password};
?>
{exp:twitter_timeline type="user" user="<?php echo $tuser; ?>" password="<?php echo $tpass; ?>" limit="3"}
a php variable set to a string-
<?php
$tuser = "username";
$tpass = "password";
?>
{exp:twitter_timeline type="user" user="<?php echo $tuser; ?>" password="<?php echo $tpass; ?>" limit="3"}
Produces the following error (twice)-
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: twitter_timeline/pi.twitter_timeline.php
Line Number: 299
posted in tech support forum: http://expressionengine.com/forums/viewthread/149536/
Comment on Bug Report
| Posted by: Greg Aker on 17 March 2010 11:11am | |
|
|
[ Permalink ]
adlur: A global variable will not work due to Template Parse Order When you set a snippet to a php variable, they need to be quoted. After the snippet is parsed, it would be:
$tuser = username
which will give you a PHP error. You can use a snippet as a tag parameter value, because snippets are parsed at the same stage as path.php global variables in 1.x. As for setting it in straight PHP. do you have PHP on input or output? PHP on input should work. -greg |
| Posted by: TPE on 17 March 2010 11:45am | |
|
|
[ Permalink ]
Hi Greg, I can’t pretend to completely understand how the parse order affects this, <?php returns Parse error: syntax error, unexpected T_STRING in /Applications/MAMP/htdocs/flounders/fbg_system/expressionengine/libraries/Functions.php(611) : eval()‘d code on line 3 while <?php returns the correct values from the snippets (as strings) however it doesn’t seem to place those values into the Twitter Timeline code- I’ve tried with the template set to input and output as: {exp:twitter_timeline type=“user” user=”<?php echo $tuser; ?>” password=”<?php echo $tpass; ?>” limit=“3” auto_link=“true”} An additional test, the following works: (with php set to input) |
| Posted by: Greg Aker on 17 March 2010 11:54am | |
|
|
[ Permalink ]
Do you have a quotation mark in your username or password? What is {twitter_username} & {twitter_password} a snippet or a global variable? |
| Posted by: TPE on 17 March 2010 11:55am | |
|
|
[ Permalink ]
No, no quotation mark in the username or password- they are snippets… |
| Posted by: Greg Aker on 17 March 2010 11:56am | |
|
|
[ Permalink ]
apologizes, I missed you saying they were snippets. Can you give me greater context here? why do you need this to be in PHP? What is your end goal? |
| Posted by: TPE on 17 March 2010 11:58am | |
|
|
[ Permalink ]
No sweat- I don’t need it to be in PHP, in fact I’d prefer it wasn’t- my goal is to place variable data (in the form of a custom field from a channel entry) into the exp:twitter_timeline call so that the Twitter username and password don’t need to be hard coded into the template… |
| Posted by: Greg Aker on 17 March 2010 12:05pm | |
|
|
[ Permalink ]
okay. Are you trying to load multiple feeds based on a page, or is this just one user feed? Why not just put the values into a snippet? I wouldn’t recommend putting it into the channel entries tag, as you’re adding some overhead of sql queries and parsing, in addition to the time needed to fetch the feed from twitter when the cache grows stale. If you want the channel entries tag to work in this instance, you’ll need to wrap the tag around the plugin. It will not work inline. -greg |
| Posted by: TPE on 17 March 2010 1:50pm | |
|
|
[ Permalink ]
It’s just one twitter feed, I would prefer to keep the username and password values in a channel entry, in order to keep the method of data entry as simple as possible. The following partially functions, the template is not throwing any errors and the created_at date is showing correctly however the {text} is not- I assume it’s looking for {text} as a custom field of the channel entry: {exp:channel:entries channel=“site-wide_ch” disable=“categories|member_data” limit=“1”} but ultimately the problem is the snippet is not providing data to the twitter_timeline call… My understanding is they are parsed before everything else? So by the time it gets to the twitter_timeline call the data from the snippets should be available? Plus, the twitter_timeline call isn’t accepting any form of string data written as the value of a variable- the only method is to hard code the username and password… |
| Posted by: Greg Aker on 29 March 2010 3:05pm | |
|
|
[ Permalink ]
adlur: I’m still not replicating your issues with the snippets on the currently released version of the public beta. Even though it does work, I would highly advise against taking the channel:entries route to populate the username and password of the twitter plugin, as you are consuming unnecessary resources with the channel:entries tag in this instance. The Channel Entries tag is indeed very powerful, but you can run into performance issues if it is used improperly. Put only the following in a bare, blank template using snippets to populate the plugin data. Please follow up by creating a related issue to the original tech support thread with a link to the test template in action http://expressionengine.com/forums/viewthread/149536/ for additional troubleshooting by the tech support staff.
{exp:twitter_timeline type="user" user="{twitter-username}" password="{twitter-password}" limit="3" auto_link="true"}Due to not being able to replicate this either way, I am marking this as not a bug, and the support staff will assist in the thread. Thanks! |
