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?
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:
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.
Use the third param of
view()like so: