Logic/Presentation separation

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












I have the following code:



<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php while($visitor = $visitors->fetch_object()) ?>
<?php $time = $visitor->time; ?>
<?php $visitor = new User($visitor->viewer_id); ?>
<?php
$this->insert('visitors/visitor',[
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time);
]);
?>
<? ?>
</div>
</div>
</div>
</div>


I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.



Can anyone help me with ideas on the way to do this logic/presentation separation?







share|improve this question

























    up vote
    3
    down vote

    favorite












    I have the following code:



    <div id="page-content">
    <div class="container-fluid">
    <div class="row">
    <div class="col-lg-11">
    <div id="featured_users></div>
    </div>
    </div>
    <div class="row">
    <div class="col-lg-11">
    <h1> Visitors </h1>
    <?php while($visitor = $visitors->fetch_object()) ?>
    <?php $time = $visitor->time; ?>
    <?php $visitor = new User($visitor->viewer_id); ?>
    <?php
    $this->insert('visitors/visitor',[
    'id' => $visitor->id,
    'profile_image' => $visitor->profile_image,
    'name' => $visitor->name,
    'time' => $time->convertToAgo($time);
    ]);
    ?>
    <? ?>
    </div>
    </div>
    </div>
    </div>


    I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.



    Can anyone help me with ideas on the way to do this logic/presentation separation?







    share|improve this question





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have the following code:



      <div id="page-content">
      <div class="container-fluid">
      <div class="row">
      <div class="col-lg-11">
      <div id="featured_users></div>
      </div>
      </div>
      <div class="row">
      <div class="col-lg-11">
      <h1> Visitors </h1>
      <?php while($visitor = $visitors->fetch_object()) ?>
      <?php $time = $visitor->time; ?>
      <?php $visitor = new User($visitor->viewer_id); ?>
      <?php
      $this->insert('visitors/visitor',[
      'id' => $visitor->id,
      'profile_image' => $visitor->profile_image,
      'name' => $visitor->name,
      'time' => $time->convertToAgo($time);
      ]);
      ?>
      <? ?>
      </div>
      </div>
      </div>
      </div>


      I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.



      Can anyone help me with ideas on the way to do this logic/presentation separation?







      share|improve this question











      I have the following code:



      <div id="page-content">
      <div class="container-fluid">
      <div class="row">
      <div class="col-lg-11">
      <div id="featured_users></div>
      </div>
      </div>
      <div class="row">
      <div class="col-lg-11">
      <h1> Visitors </h1>
      <?php while($visitor = $visitors->fetch_object()) ?>
      <?php $time = $visitor->time; ?>
      <?php $visitor = new User($visitor->viewer_id); ?>
      <?php
      $this->insert('visitors/visitor',[
      'id' => $visitor->id,
      'profile_image' => $visitor->profile_image,
      'name' => $visitor->name,
      'time' => $time->convertToAgo($time);
      ]);
      ?>
      <? ?>
      </div>
      </div>
      </div>
      </div>


      I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.



      Can anyone help me with ideas on the way to do this logic/presentation separation?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Feb 8 at 23:55









      Ivan Grigorov

      255




      255




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










           <?php
          // this code goes into your controller
          $visitor_rows = ;

          // lets do all the hard work here
          while($visitor = $visitors->fetch_object())
          $time = $visitor->time;
          $visitor = new User($visitor->viewer_id);
          $visitor_rows = [
          'id' => $visitor->id,
          'profile_image' => $visitor->profile_image,
          'name' => $visitor->name,
          'time' => $time->convertToAgo($time),
          ]);


          // the template only needs to know about $visitor_rows now
          ?>


          <!-- the template is now a lot simpler to follow and understand -->
          <!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
          <div id="page-content">
          <div class="container-fluid">
          <div class="row">
          <div class="col-lg-11">
          <div id="featured_users"></div>
          </div>
          </div>
          <div class="row">
          <div class="col-lg-11">
          <h1> Visitors </h1>
          <?php foreach ($visitor_rows as $row): ?>
          <?= $this->insert('visitors/visitor', $row) ?>
          <?php endforeach ?>
          </div>
          </div>
          </div>
          </div>





          share|improve this answer























            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "196"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187134%2flogic-presentation-separation%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










             <?php
            // this code goes into your controller
            $visitor_rows = ;

            // lets do all the hard work here
            while($visitor = $visitors->fetch_object())
            $time = $visitor->time;
            $visitor = new User($visitor->viewer_id);
            $visitor_rows = [
            'id' => $visitor->id,
            'profile_image' => $visitor->profile_image,
            'name' => $visitor->name,
            'time' => $time->convertToAgo($time),
            ]);


            // the template only needs to know about $visitor_rows now
            ?>


            <!-- the template is now a lot simpler to follow and understand -->
            <!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
            <div id="page-content">
            <div class="container-fluid">
            <div class="row">
            <div class="col-lg-11">
            <div id="featured_users"></div>
            </div>
            </div>
            <div class="row">
            <div class="col-lg-11">
            <h1> Visitors </h1>
            <?php foreach ($visitor_rows as $row): ?>
            <?= $this->insert('visitors/visitor', $row) ?>
            <?php endforeach ?>
            </div>
            </div>
            </div>
            </div>





            share|improve this answer



























              up vote
              1
              down vote



              accepted










               <?php
              // this code goes into your controller
              $visitor_rows = ;

              // lets do all the hard work here
              while($visitor = $visitors->fetch_object())
              $time = $visitor->time;
              $visitor = new User($visitor->viewer_id);
              $visitor_rows = [
              'id' => $visitor->id,
              'profile_image' => $visitor->profile_image,
              'name' => $visitor->name,
              'time' => $time->convertToAgo($time),
              ]);


              // the template only needs to know about $visitor_rows now
              ?>


              <!-- the template is now a lot simpler to follow and understand -->
              <!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
              <div id="page-content">
              <div class="container-fluid">
              <div class="row">
              <div class="col-lg-11">
              <div id="featured_users"></div>
              </div>
              </div>
              <div class="row">
              <div class="col-lg-11">
              <h1> Visitors </h1>
              <?php foreach ($visitor_rows as $row): ?>
              <?= $this->insert('visitors/visitor', $row) ?>
              <?php endforeach ?>
              </div>
              </div>
              </div>
              </div>





              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                 <?php
                // this code goes into your controller
                $visitor_rows = ;

                // lets do all the hard work here
                while($visitor = $visitors->fetch_object())
                $time = $visitor->time;
                $visitor = new User($visitor->viewer_id);
                $visitor_rows = [
                'id' => $visitor->id,
                'profile_image' => $visitor->profile_image,
                'name' => $visitor->name,
                'time' => $time->convertToAgo($time),
                ]);


                // the template only needs to know about $visitor_rows now
                ?>


                <!-- the template is now a lot simpler to follow and understand -->
                <!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
                <div id="page-content">
                <div class="container-fluid">
                <div class="row">
                <div class="col-lg-11">
                <div id="featured_users"></div>
                </div>
                </div>
                <div class="row">
                <div class="col-lg-11">
                <h1> Visitors </h1>
                <?php foreach ($visitor_rows as $row): ?>
                <?= $this->insert('visitors/visitor', $row) ?>
                <?php endforeach ?>
                </div>
                </div>
                </div>
                </div>





                share|improve this answer















                 <?php
                // this code goes into your controller
                $visitor_rows = ;

                // lets do all the hard work here
                while($visitor = $visitors->fetch_object())
                $time = $visitor->time;
                $visitor = new User($visitor->viewer_id);
                $visitor_rows = [
                'id' => $visitor->id,
                'profile_image' => $visitor->profile_image,
                'name' => $visitor->name,
                'time' => $time->convertToAgo($time),
                ]);


                // the template only needs to know about $visitor_rows now
                ?>


                <!-- the template is now a lot simpler to follow and understand -->
                <!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
                <div id="page-content">
                <div class="container-fluid">
                <div class="row">
                <div class="col-lg-11">
                <div id="featured_users"></div>
                </div>
                </div>
                <div class="row">
                <div class="col-lg-11">
                <h1> Visitors </h1>
                <?php foreach ($visitor_rows as $row): ?>
                <?= $this->insert('visitors/visitor', $row) ?>
                <?php endforeach ?>
                </div>
                </div>
                </div>
                </div>






                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Feb 9 at 7:42









                Your Common Sense

                2,435524




                2,435524











                answered Feb 9 at 6:36









                bumperbox

                1,800614




                1,800614






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187134%2flogic-presentation-separation%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Chat program with C++ and SFML

                    Function to Return a JSON Like Objects Using VBA Collections and Arrays

                    Will my employers contract hold up in court?