Need help with New-Lines/Carriage-Returns in plugin parameters
Posted: 07 November 2007 01:47 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  14
Joined  05-24-2007

Hello

I’m developing a plugin that proccess a custom field of a weblog. The plugin doesn’t need tag pairs, so the custom field is passed as a parameter

{exp:cdd_utils:songs song_list="{song_list}"}

That custom field is a textarea, and has a list of songs, one per line.

But when I retrieve that parameter,

$TMPL->fetch_param('song_list')


all I get is a string with all the songs in one line.

Am I doing something wrong?

Thank You

Profile
 
 
Posted: 07 November 2007 02:35 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

Because you might not be able to always guarantee the format of the incoming data would recommend you go down the tag pair route and do some additional parsing to ensure it’s suitability for any use you have for it.

But to revert, how are you seeing this data? echo -> view source?

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 07 November 2007 03:32 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  14
Joined  05-24-2007

the_butcher

Thank You for the reply.

I didn’t understand very well why I might not be able to always guarantee the format of the incoming data?

In the Admin Panel, when I publish a new Entry there is a <textarea> where I’ll write a song on each line, and always that same way. So the data should be coming in the same format in every entry.

Now, to see how the data is coming, I just return it, and then check the rendered template, which shows all in one line.

If you want more info on what does my plugin, It simply generates a tracklist, adding additional data to it. But if I focus on where do I have the main issue, I can just tell you that what I can’t do right now is to put the tracklist as an ordered list.

In the Publish page, I write:

Song 1
Song 2
Song 3
Song 4
Song 5

In the template, I write:

{exp:cdd_utils:songs song_list="{song_list}"}

The rendered template should print:

<ol>
<
li>Song 1</li>
<
li>Song 2</li>
<
li>Song 3</li>
<
li>Song 4</li>
<
li>Song 5</li>
</
ol>

So I need to get every line of the input, to add the <li> tags and the additional information.

Once I can do that, I’ll add all the other features, but now I just want to finish that first step.

Thank You

Profile
 
 
Posted: 07 November 2007 05:05 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

Most (all?) browsers will show it all on one line even if there are new line characters in the output, check the page source to confirm if it IS all on one line.

I think what I was trying to say before is that you may end up having a stray ” in there at some point, and that’ll pretty much break your plugin.

 Signature 

(a.k.a the_butcher)

Profile
 
 
Posted: 12 November 2007 07:34 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1330
Joined  02-12-2003

This is along the same lines as using:

$variable = 'Something unknown here...';

Instead of:

$variable = <<<CODE
Something unknown here...
CODE;

If you can’t guarantee that the variable you are dealing with isn’t going to contain a quote or return carriage that will potentially cause your plugin to fail then its much safer to use tag pairs like the_butcher is suggesting.

Give what we know of what you are trying to do I really wouldn’t recommend using parameters like you are trying to do.

Jamie

Profile
 
 
Posted: 12 February 2008 06:55 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  281
Joined  12-09-2006

Let me know when the plugin is ready. It’s just what i’m looking for.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65013 Total Logged-in Users: 56
Total Topics: 82081 Total Anonymous Users: 36
Total Replies: 441128 Total Guests: 316
Total Posts: 523209    
Members ( View Memberlist )