We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Need help with New-Lines/Carriage-Returns in plugin parameters

Development and Programming

Gonzalingui's avatar
Gonzalingui
13 posts
17 years ago
Gonzalingui's avatar Gonzalingui

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

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

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?

       
Gonzalingui's avatar
Gonzalingui
13 posts
17 years ago
Gonzalingui's avatar Gonzalingui

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

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

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.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

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

       
textdriven's avatar
textdriven
107 posts
17 years ago
textdriven's avatar textdriven

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.