1

Been trying to go bout how to accomplish dividing content on view output.

I'm loading records from Mysql, inserting values into HEREDOC to then output to view.

I want to display only a certain amount of characters in a particular row within the HEREDOC, hide the rest from view on DOM.

enter image description here

I tried using a function like this within the HEREDOC to insert a "More" link after certain amount of characters.

I've tried a couple methods:

1

<<<EOT
<div id="$id_op">
    {substr_replace($contents, "More", 400)}
</div>

EOT;

2

<<<EOT
    <div id="$id_op">
        {${substr_replace($contents, "More", 400)}}
    </div>

EOT;

There might be other better methods to accomplish this. For now I want to load the record completely into dom but hide part of it until user have clicked a jQuery selector.

Any help / direction will be truly appreciated.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
Codex73
  • 5,690
  • 11
  • 56
  • 76

2 Answers2

1

Compute any variable content before starting the HEREDOC, then insert the variables into the string as you go.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
1

Functions does not execute in HEREDOC. This will work

$div = substr_replace($contents, "More", 400);
$data = <<<EOT
<div id="$id_op">
    $div
</div>
EOT;
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187