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

  • SEARCH
  • Home
  • 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 8676325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:10:00+00:00 2026-06-12T20:10:00+00:00

Not sure if it’s possible, but can you use if statements inside a template?

  • 0

Not sure if it’s possible, but can you use if statements inside a template?

So if a phone number does not have a value I don’t want to display that sentence at all…

<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset="utf-8"/>
    <title>{form_title}</title>

</head>


<body>
    <p>You received the following message from {name} through the Gossip Cakes' contact form.</p>

    <p>Their email is {email}</p>

    <p>Their phone number is {phone}</p>

    <p>The message: {message}</p>

</body>


</html>

I guess I could use straight php, but is there a method of returning the html of a view?

  • 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. Editorial Team
    Editorial Team
    2026-06-12T20:10:01+00:00Added an answer on June 12, 2026 at 8:10 pm

    Assuming you’re using CI’s built in parser, you have to prep all the variables beforehand. There is no support for conditions, variable assignment, or anything beyond loops and basic token replacement at this time.

    To do this in CI, you’d have to prep the whole message, something like this in your controller:

    if ($phone) {
        $data['phone_msg'] = "<p>Their phone number is $phone</p>";
    } else {
        $data['phone_msg'] = '';
    }
    

    Not a good solution. Personally I’d recommend Twig if you’re looking for a nice template parser. Your idea of “I guess I could use straight PHP” is also a very good one.

    is there a method of returning the html of a view?

    Use the third param of view() like so:

    $html = $this->load->view('myview', $mydata, TRUE);
    echo 'Here is the HTML:';
    echo $html;
    // OR...
    echo $this->parser->parse_string($html, NULL, TRUE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if this is possible in Python, but I'd like to have an
Not sure if I can word this right but here we go. I have
Not sure how to ask this, but i'll give it a try: I have
Not sure if this is possible: I want to use datatables to manipulate my
not sure how it can be done, but how can I edit the urls
Not sure if I can frame my question right. I have a page which
Not sure if this is even possible, but I think it's worth asking. What
not sure what i'm missing, but here ti go's: i have a floating left
Not sure what parallel programing means... but I have two thoughts of that Process
Not sure why I can show jpg images in the simulator but not when

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.