4images Forum & Community

4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: trez on October 29, 2011, 08:21:09 PM

Title: Wondering: {if x_value == value} x {endif x_value}
Post by: trez on October 29, 2011, 08:21:09 PM
I am just wondering, if 4images supporting that? (I searched the whole site but didn't find any related topic)

For example, you have an image, with an additional image field (image_camera) with a value (for example) of "Canon". 

Then in details, we could use {if image_camera == "Canon"} some information {endif} witch will display the information only if image_camera is "Canon".
Hope you got the example.

So is 4images supporting this and I just don't see/find it?


Title: Re: Wondering: {if x_value == value} x {endif x_value}
Post by: V@no on October 29, 2011, 09:47:24 PM
No, 4images doesn't support complex conditions, however you can use PHP code inside template. Just keep in mind, that template's code executed inside a function, therefor non-global variables are not accessible there without using global keyword (global $blah;)
Registered template tags can be access via $this->val_cache array

Here is an example you can use your additional field in template:

Code: [Select]
<div>
  your template text/code
</div>
<div>
<?php
if ($this->val_cache['image_camera'] == "Canon")
{
?>

  some information witch will display the information only if image_camera is "Canon".
</div>
<?php
//don't forget closing bracket, otherwise you'll get parse error!
else
{
?>

  this will be showed if the camera is not Canon.
<?php
}
?>

</div>

A long time ago I had this theory that since 4images converts all {if blah} into PHP code anyway it would make sense that if template had all {if blah} already converted into PHP then the template parsing will be faster...for some reason it didn't turn out to be true, at least with fresh 4images v1.7 and default template.
Title: Re: Wondering: {if x_value == value} x {endif x_value}
Post by: trez on October 29, 2011, 10:43:18 PM
Great, thanks, that will help me ;)