Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Strip tag to only remove blank lines?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 76

PostPosted: Sat Nov 19, 2016 11:44 am    Post subject: Strip tag to only remove blank lines? Reply with quote

EDIT, i am aware my 'output' should not contain Smarty code - but i hope you understand what Im after.

http://www.smarty.net/docsv2/en/language.function.strip.tpl

Hello.

I do know the above strip command, however i was wondering if there was a command to remove blank lines from the output WITHOUT putting the 2nd/3rd line on the same line as the first...

I want the html code to remove blank lines - But keep the 2nd line on the 2nd line...

example :- ORIGINAL

Code:


{* the following will be all run into one line upon output *}
{strip}
<table border='0'>


 <tr>


  <td>
   <a href="{$url}">
    <font color="red">This is a test</font>


   </a>
  </td>

 </tr>


</table>
{/strip}



The STRIP command does this :-

Code:

{* the following will be all run into one line upon output *}
{strip}
<table border='0'><tr><td><a href="{$url}"><font color="red">This is a test</font></a></td></tr></table>
{/strip}


What im after - is this :-


Code:

{* the following will be all run into one line upon output *}
{strip}
<table border='0'>
 <tr>
  <td>
   <a href="{$url}">
    <font color="red">This is a test</font>
   </a>
  </td>
 </tr>
</table>
{/strip}



Has smarty got a command that has this ability ?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Nov 19, 2016 11:56 am    Post subject: Reply with quote

The aim of {strip} tag is to minimize content-length. Not to pretty-print it.
What you're after is something like http://php.net/tidy
Also, font tag is not supported, and weren't supported by official standards, for a very long time.
https://www.w3.org/TR/html4/present/graphics.html#edef-FONT
http://www.w3schools.com/tags/tag_font.asp
Back to top
View user's profile Send private message
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 76

PostPosted: Sat Nov 19, 2016 12:23 pm    Post subject: Reply with quote

Thanks..

i guess i'll have to live with the multiple spaces, or hunt them down & remove them...

(im not after 'pretty' - Just to remove excess spaces)

PS the FONT tag was/is shown in your smarty documentation (test)...

http://www.smarty.net/docsv2/en/language.function.strip.tpl
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Nov 19, 2016 12:29 pm    Post subject: Reply with quote

{strip} removes excess whitespaces BETWEEN the start and end tags.
I don't understand your "have to live with the multiple spaces". Sorry.
Code:
<?php

require_once 'smarty-config.php';

$smarty->display(__FILE__);

__HALT_COMPILER();
?>{strip}
<table border='0'>
 <tr>
  <td>
   <a href="{$url}">
    <font color="red">This is a test</font>
   </a>
  </td>
 </tr>
</table>
{/strip}


Code:
$ php -f ./strip.php 2> nul
<table border='0'><tr><td><a href=""><font color="red">This is a test</font></a></td></tr></table>
Back to top
View user's profile Send private message
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 76

PostPosted: Sat Nov 19, 2016 2:22 pm    Post subject: Reply with quote

AnrDaemon wrote:
{strip} removes excess whitespaces BETWEEN the start and end tags.
I don't understand your "have to live with the multiple spaces". Sorry.


The thing i do want, i cannot have - So i have to live with it (what i dont have)....

AnrDaemon wrote:


[code]
[code]$ php -f ./strip.php 2> nul
<table border='0'><tr><td><a href=""><font color="red">This is a test</font></a></td></tr></table>
[/code]



Thats what i do not want - i dont want 5,10,20+ HTML commands all in one paragraph/line of text.....

I want each line of my HTML code on each / separate line of HTML source code (if i look at the source code of HTML output)... HOWEVER - any blank lines (with no text or html code) to be removed.


NOTE: if I put 2 or more HTML commands onto one line - then thats my problem, 2 html commands of HTML code will display on the one line...

if i have 3 HTML comands in one line - it will display 3 html commands - i dont need/want the smarty compiler to determine where to split html commands..

if i have 10 lines of codes - But 5 lines are blank/un-used, i will get 5 lines of code as a result - the blank lines are removed...
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Nov 19, 2016 5:09 pm    Post subject: Reply with quote

Write your own block based on HTML Tidy extension.
See http://www.smarty.net/docs/en/plugins.tpl and specifically http://www.smarty.net/docs/en/plugins.block.functions.tpl

And regarding your notes…
What you want is basically a nonsense. If you desire such "no alteration" so much, then just write your templates that way and don't use any formatting codes.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP