String variable with line breaks won't display or display formatted.

rainmotorsports

Well-known member
I have a string extracted from a given image with line breaks intact like so:
PunkBuster Screenshot (�) BF4 XP2/Levels/XP2_001/XP2_001
1515139 :25200 **ALL RUSH MAPS 24/7 | BF4 + DLC | TBGCLAN.COM | GAMEME
*15048ed5751dcacb2xxxxxxxxxx* xgp15a3
Attempted: w=320 X h=240 at (x=50%,y=50%)
Resulting: w=320 X h=200 sample=1

This is displayed from an associative array in the template like this:
Code:
<xen:foreach loop="$globFiles" key="$img" value="$text">
{$img}
<p><img src="http://www.tbgclan.com/data/pbss/{$img}"></p>
{$text}
</xen:foreach>

I couldn't get $text to display at all so I did a dump using {xen:helper dump, $text} and got this:
Code:
string(261) "PunkBuster Screenshot (�) BF4  XP2/Levels/XP2_001/XP2_001
1515139 :25200 **ALL RUSH MAPS 24/7 | BF4 + DLC | TBGCLAN.COM | GAMEME
*15048ed5751dcacb2xxxxxxxxxx* xgp15a3
Attempted: w=320 X h=240 at (x=50%,y=50%)
Resulting: w=320 X h=200 sample=1
"

So I am not sure how to go about this but {xen:raw $text} gives me:
Code:
PunkBuster Screenshot (�) BF4 XP2/Levels/XP2_001/XP2_001 1515139 74.91.115.207:25200 **ALL RUSH MAPS 24/7 | BF4 + DLC | TBGCLAN.COM | GAMEME *15048ed5751dcacb2a4cdab03040f158* xgp15a3 Attempted: w=320 X h=240 at (x=50%,y=50%) Resulting: w=320 X h=200 sample=1

Is there anyway to put this variable in there with its line breaks intact? I mean they seem to show in the dump just the way I would want it.
 
Last edited:
I think you want:

Code:
{xen:string nl2br, $text}

That should convert the line breaks into <br /> tags.
 
I had actually tried that pretty sure it was you in another thread and for whatever case it was it worked. But here it displays nothing. Same as doing {$text}

Is there any prerequisites for the template helper to be available? The template is the index of a plugin the output is from a responseView for the controller. Not sure if I am missing anything that would cause the helper to not work or something silly like that.

Edit - to be honest it can't be the helper not being available can it because putting text in place of the variable inside the helper causes the text to be displayed.
 
So dumping $text gives you the output you posted above, but using {xen:string nl2br, $text} returns nothing?

What if you do {xen:helper dump, {xen:string nl2br, $text}}
 
Sigh, yes but as far as testing that its going to be a minute. I changed the line breaks in my cron script to html breaks as a test and even though I reverted the change all off a sudden the cron no longer works throwing the same error I have in my thread from earlier lol.

I deleted the files in the ftp so until the cron starts working again I have nothing to test from.
 
So dumping $text gives you the output you posted above, but using {xen:string nl2br, $text} returns nothing?

What if you do {xen:helper dump, {xen:string nl2br, $text}}

Okay completely changed the code I am using to get the text so that it works, nightmare.

Code:
string(296) "PunkBuster Screenshot (�) BF4  Levels/MP/MP_TheDish/MP_TheDish<br />
9719205 74.91.113.5:25200 **AIR MAPS ONLY CONQUEST 24/7 | TBGCLAN.COM | GAMEME<br />
*a33b467091d7602d807689b4ebc29e72* WaterBear777<br />
Attempted: w=320 X h=240 at (x=50%,y=50%)<br />
Resulting: w=320 X h=200 sample=1<br />
"

Is what I am getting and yes its still not showing. So here is a screen shot of trying all of these:
{$text}
{xen:string nl2br, $text}
{xen:helper dump, {xen:string nl2br, $text}}
{xen:raw $text}

Shot:
nl2br.webp
The first 2 are the ones not displaying the last 2 are displaying.
 
Okay quick update, put the nl2br into the php thats returning the text it is now formatting the {xen:raw $text}, Im pretty sure I can work with that.

Is it weird the first 2 not working though?
 
It is slightly weird, but the interesting thing is the third one shows that the nl2br is working perfectly. Notice the <br /> at the end of each line. On the basis of the second one, in theory, this should work:

{xen: raw {xen:string nl2br, $text}}
 
It is slightly weird, but the interesting thing is the third one shows that the nl2br is working perfectly. Notice the <br /> at the end of each line. On the basis of the second one, in theory, this should work:

{xen: raw {xen:string nl2br, $text}}

Alright thanks, I believe you are correct on that theory. I appreciate your time I know you are a busy man.
 
I'm having a similar problem with this.

When I do the above the HTML output shows the literal "sometext<br />somemoretext". The <br /> doesn't cause a line break, like it should.

So then I use javascript (note: my text is in between a <span> tag) to do this: document.getElementById("xxx").innerHTML = document.getElementById("xxx").innerHTML. It forces the DOM to re-eval and the <br /> works now (showing two lines of text now).

But the two lines are totally out of alignment. So I inspected the element and there is a lot of extra spaces in the string. Is there a xen trim() function I can use to clean that up?

Also why is the <br /> initially not working until I copy it to itself?

I'm not new to coding, but very new to xen.
 
Top Bottom