Breaking lines in a date attribute when displaying in front-end

Asked

Viewed 280 times

0

Within a table I have the following structure:

<td>
<a href="#" data-toggle="popover" title="Dados" data-trigger="focus"
data-content=" <?php 
echo $BlobParams[0].'<br>';
echo $BlobParams[1].'<br>';
echo $BlobParams[2].'<br>';
echo $BlobParams[3].'<br>';
echo $BlobParams[4].'<br>';
echo $BlobParams[5].'<br>';
echo $BlobParams[6];
?>">
Parametros
</a>
</td>

In the data-content data appears from a array, would like one item to appear below the other. I tried to use the <br> in many ways, but it didn’t work. The <br> appears written on the screen.

  • 1

    What are you using to display this message? It supports HTML elements?

  • Have you tried the predefined constant PHP_EOL in place of <br> ? Like this: echo $BlobParams[0]. PHP_EOL;

  • You will have to put the line break "inside the variable".

  • You search for this break by displaying the page code, right?

  • 1

    Have you tried ' r' or ' n' ? This might help you https://pt.wikipedia.org/wiki/Nova_line

5 answers

0

On the level of curiosity and also not sure if it is the best way, I managed to solve the case as follows in the call of the method popover:

$('[data-toggle="popover"]').popover({html: true})

I added the html:true that made it possible for me to use the <br> normally.

  • I was curious. Could later by a screen print. What really changed and how it was before.

  • Actually in this field appears the parameters (filters used to generate a report), and these items were all appearing next to each other only separated pro " - " , and was very confused. Then came the idea of separating each item of the Array into a line.

  • This when you hover over the link? I say this, because in the test I did it breaks the items by line, but only in the code view. Anyway, I’m glad you solved the problem.

  • 1

    It would be by clicking even ..... click appears a Popover with the information and clicking anywhere it closes. Just not to get too much information on the screen. So they only appear when the user clicks on.

0

A new alternative to writing the data. If the person does not use any filter parameter, it will not appear and will not be a blank line

<?php
foreach($BlobParams as $blobs){
if($blobs != ""){
echo "- ".$blobs."<br>";
}
}
?>

0

It would be interesting for you to adapt your code as follows:

Add the option html: true in the call of the.

// Habilita o html no conteúdo do popover
$('#example').popover({html: true})
<td>
  <?php
    $content = '';

    // Cria o conteúdo com <br> de forma dinâmica
    foreach($BlobParams as $BlobParam) {
      $content .= $BlobParam . '<br>';
    }

    // Remove o espaçamento <br> no final da string 
    $content = rtrim($content, '<br>');
  ?>
  <a 
    href="#" 
    data-toggle="popover" 
    title="Dados" 
    data-trigger="focus"
    data-content="<?php echo $content; ?>">
    Parametros
  </a>
</td>

0

PHP_EOL is ostensibly used to find the new line character in a multi-platform compatible manner. PHP_EOL represents the finishing character for the current system, unlike an html tag tag like the tag <br>.

Predefined constant PHP_EOL(string) - 'End Of Line'. Available since PHP 5.0.2, according to the PHP manual.

Use in your case:

<td>
    <a href="#" data-toggle="popover" title="Dados" data-trigger="focus"
            data-content="<?php echo PHP_EOL .
                            $BlobParams[0]. PHP_EOL .
                            $BlobParams[1]. PHP_EOL .
                            $BlobParams[3]. PHP_EOL .
                            $BlobParams[2]. PHP_EOL .
                            $BlobParams[4]. PHP_EOL .
                            $BlobParams[5]. PHP_EOL .
                            $BlobParams[6]; ?>"> Parametros</a> 
</td>
  • Hello... I appreciate the help... but the data keeps popping up next to each other.

  • At the level of curiosity and also do not know if it is the best way, I managed to solve the case as follows in the call of the function " $('[data-toggle="Popover"]'). Popover({html: true}); ", I added html:true. With this I could use <br> normally.

  • You can answer your own question with the solution you found and select it as the correct answer to your problem.

  • In your question, could along with the code by a print(screen) of your problem. And in the answer, also a print with the problem solved and more the code. I think it would be clearer. Greetings.

-1

You tbm can set the attribute value as a json with the whole array $BlobParams. This way focuses easier to recover the values in js.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.