Developer forum

Forum » Feature requests » Remove linebreaks tag extention

Remove linebreaks tag extention

Nuno Aguiar
Reply

Hi,

 

Would be great if we had a tag extention to remove linebreaks. Basically "minify" the output. Here are some examples:

Code:

marker_infoText:'<!--@ItemPublisher:Item.PointDescription-->'
Output:
marker_infoText:'Rua Senhora Porto 930, 4250-453<br />
<a href="/">Porto</a>'

Code:

marker_infoText:'<!--@ItemPublisher:Item.PointDescription.Replace("<br />","")-->'
Output:
marker_infoText:'Rua Senhora Porto 930, 4250-453
<a href="/">Porto</a>'

Code:
marker_infoText:'<!--@ItemPublisher:Item.PointDescription.HtmlEncoded()-->'
Output:
marker_infoText:'Rua Senhora Porto 930, 4250-453&lt;br /&gt;
&lt;a href=&quot;/&quot;&gt;Porto&lt;/a&gt;'

Code:

marker_infoText:'<!--@ItemPublisher:Item.PointDescription.StripHtml()-->'
Output:
marker_infoText:'Rua Senhora Porto 930, 4250-453
Porto'

 

We were using tags within js to create Google Maps markers, and cannot apply it directly to the var, since the tag "keeps" linebreak

 

BR, Nuno

 

 


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

I've changed the replace so it can do .Replace("crlf", "") on any tag  and that will remove the line breaks of the output.

 

The crlf have to be the only parameter on the original string, you cannot do .Replace("SometSTRINGcrlfOTHERstring", "")

 

BR Nicolai

Votes for this answer: 1
 
Nicolai Høeg Pedersen
Reply

TFS#13975 out in 8.4

 
Nuno Aguiar
Reply

Hi Nicolai,

 

I think that will do the trick :) Don't forget to place it in the documentation afertwards.

 

Best Regards,

Nuno

 
Morten Bengtson
Reply

Why not use Regex.Replace for this tag extension instead of making this weird keyword hack? That way we can replace anything we can think of by using a regular expression.

I think that adding new extensions like RemoveLineBreaks() and NormalizeWhitespace() would be a better solution than adding custom keywords to the replace extension.

Just sayin' :)

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I agree. Explicit methods and regex support would make much more sense. What if I have a unix-type input that uses only a line break but not a carriage return (or vice versa; can't recall). Using a regex would make this much simpler and less "hacky"....

 

Imar

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Morten and Imar

 

Of course - great input and aa very good point. I've changed the Replace extension method to be regex based instead of introducing the weird string.

 

 

So Nuno, you would have to do Tag.Replace('\n\r','')

 

Thanks and merry x-mas everyone.

 

Nicolai

Votes for this answer: 1
 
Nuno Aguiar
Reply

Hi Guys,

 

Even better solution.

 

BR,

Nuno

 
Fredrik Falkesand
Reply

Hi everyone.

Is this a thing yet?
I'm trying to write a tag to a JavaScript variable.

@{
           var prodName = GetString("Ecom:Product.Name").Replace("\n\r", "");
                    
           <text>var prodName = "</text>@prodName2<text>";</text>
   }


This does not work for me, version: 8.4.1.19.

The result is:

var prodName = "Elementskydd Elsa 
";


You can se that just after the "Elementskydd Elsa" there is a line break.

Any help would be appreciated =)

// Fredrik

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Fredrik,

If the source contains a proper line break, it's \r\n you're after, not \n\r.

Cheers,

Imar