CodeIgniter Forums

Full Version: Using <!--- ---> instead of <?php ?> in view files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]EEssam[/eluser]
Hi guys,

I don't want to use Smarty or something like it. I just want to use <!---=$var---> and <!--- foreach ($array as $key): ---> instead of <?= $var ?> and <?php foreach ($array as $key): ?>.

How is that possible?

Please help.

El Forum

[eluser]Developer13[/eluser]
You say you don't want to use Smarty, so I assume that means you don't want to use CodeIgniter's built in Template Parser, which allows you to use your {vars} in curly braces.

If my assumption is correct, then I'd say you *cannot* do this... unless you want to develop your own template parser, which if you did, why not just use one that's already out there?

I always find myself asking "why" in my posts, but why would you want to use <!--=var --> instead of <?=$var;?>?

El Forum

[eluser]EEssam[/eluser]
Hi,

Yes, I would like to use the built-in parser but it doesn't support conditional statements!!! Sad

{if $user_logged_in}
...
{else}
...
{/if}

Edit: As for why I don't want to use PHP, it just doesn't look too professional in a commercial product Wink

Thanks.

El Forum

[eluser]Developer13[/eluser]
Gotcha...

You may not particularly be so worried about it, but keep in mind that the more you can do without having template parsers doing what natural PHP can do, the faster your script is going to be overall.

To me, this is a good enough reason to use <? pure_php_conditionals ?> in my views. I think there might be a template parser class for CI floating around out there that supports conditionals... but if I remember right, I tried it some time back and it didn't support nested conditionals.

El Forum

[eluser]EEssam[/eluser]
OK, I'm convinced but I heard short tags will be deprecated in PHP 6.

Is that true?

El Forum

[eluser]Developer13[/eluser]
Hmmmm... I'm not sure about that, haven't heard one way or the other (crap man, I'm still trying to catch up with 5)... but either way, it'd be safest to use <?php instead anyway.

El Forum

[eluser]textnotspeech[/eluser]
I'm crying. I hope your wrong about short tags in PHP 6. I love short tags. They're sexy.

El Forum

[eluser]EEssam[/eluser]
I think I'll use <? for now. For sure I'll be releasing a few major versions until PHP 6 is released.

Anyway, CI has this option in the main config.php file:

/*
|--------------------------------------------------------------------------
| Rewrite PHP Short Tags
|--------------------------------------------------------------------------
|
| If your PHP installation does not have short tag support enabled CI
| can rewrite the tags on-the-fly, enabling you to utilize that syntax
| in your view files. Options are TRUE or FALSE (boolean)
|
*/
$config['rewrite_short_tags'] = FALSE;

(loops and if statements are not working when short tag is not enabled and this option is set to TRUE. <?= ?> is working though.)

El Forum

[eluser]ray73864[/eluser]
short tags will be deprecated in PHP6, but not PHP short tags. The PHP team is dropping the ASP short tags '<% %>' so you will still be able to use '&lt;?= ?&gt;'

El Forum

[eluser]textnotspeech[/eluser]
Whew, I thought that seemed like a weird move. I was starting to think there was something wrong with short tags.
Pages: 1 2