Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 65609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:58:24+00:00 2026-05-10T18:58:24+00:00

Talking from a ‘best practice’ point of view, what do you think is the

  • 0

Talking from a ‘best practice’ point of view, what do you think is the best way to insert HTML using PHP. For the moment I use one of the following methods (mostly the latter), but I’m curious to know which you think is best.

<?php   if($a){ ?> [SOME MARKUP] <?php   }   else{ ?> [SOME OTHER MARKUP] <?php   } ?> 

Opposed to:

<?php   unset($out);   if($a) $out = '[SOME MARKUP]';   else $out = '[OTHER MARKUP]';   print $out; ?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:58:24+00:00Added an answer on May 10, 2026 at 6:58 pm

    If you are going to do things that way, you want to separate your logic and design, true.

    But you don’t need to use Smarty to do this.

    Priority is about mindset. I have seen people do shocking things in Smarty, and it eventually turns into people developing sites in Smarty, and then some bright spark will decide they need to write a template engine in Smarty (Never underestimate the potential of a dumb idea).

    If you break your code into two parts and force yourself to adhere to a standard, then you’ll get much better performance.

    PageLogic.php

    <?php     $pageData = (object)(array());  // Handy trick I learnt.     /* Logic Goes here */    $pageData->foo = SomeValue;    ob_start();   require('layout.php');   ob_end_flush(); 

    Layout.php

     <html>    <!-- etc -->    <?php for ( $i = 1; $i < 10; $i++ ){ ?>     <?php echo $pageData->foo[$i]; ?>    <?php } ?>    <!-- etc --> </html> 

    PHP Was written as a templating engine, so you at least should try to use it for its designed task before assessing whether or not you need to delve into Smarty.


    Moreover, if you decide to use a templating engine, try get one that escapes HTML by default and you ‘opt out’ instead of ‘opt in.’ You’ll save yourself a lot of XSS headaches. Smarty is weak in this respect, and because of this, there are a lot of content-naïve templates written in it.

    {if $cond}     {$dangerous_value} {else}     {$equally_dangerous_value} {/if} 

    Is generally how Smarty templates go. The problem is $dangerous_value can be arbitrary HTML and this just leads to even more bad coding practices with untraceable spaghetti code everywhere.

    Any template language you consider should cater to this concern. e.g.:

    {$code_gets_escaped}  {{$code_gets_escaped_as_a_uri}} {{{$dangerous_bare_code}}} 

    This way, your potential doorways for exploitation are easily discernible in the template, as opposed to the doorway to exploitation being the DEFAULT behaviour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The following is part of the List interface (which ArrayList… May 11, 2026 at 10:13 am
  • added an answer This Peepcode plugin patterns pdf actually answered all my questions;… May 11, 2026 at 10:13 am
  • added an answer It wasn't dropped. Simply not included. Though it is highly… May 11, 2026 at 10:13 am

Related Questions

Talking from a 'best practice' point of view, what do you think is the
Taking advice from this post , I purchased a copy of 'The C Programming
I am taking in a string from user input, and splitting it on whitespace
Taking over some code from my predecessor and I found a query that uses
I was listening to the Hansel Minutes podcast from 11/24 talking about Moonlight. To
Talking about hibernate and others ORMs, the ORMs evangelists talk about SQL like the
I'm obviously not talking about a full solution, but just a good starting point
What I'm talking about here are nested classes. Essentially, I have two classes that
I'm not talking about bug tracking software (like Bugzilla or Jira). I'm looking for
I'm not talking about tools that let one view a page in combinations of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.