vendredi 27 mai 2016

php best practices for returning multiple lines of content in an IF statement

I am writing a php plugin for wordpress. I'm trying to be mindful of clean coding and want to know the best practice for returning several lines of HTML code in an IF statement.

Obviously I know about echo but I thought I had seen a technique like this used, but it doesn't seem to work for me. The idea being that you create several $content variables and then return it outside of the IF statement.

function signup() {
    if(!Skizzar_Registration::is_skizzar_site_active()) {
        $content = '<div class="signup">';
        $content .= '<h1>Sign up</h1>';
        $content .= '</div>';
    } else {
        $content = '<div class="signed_up">you are already signed up</div>';
    }

    return $content;

}

Currently though this returns nothing when I call the function

Aucun commentaire:

Enregistrer un commentaire