Author Topic: Wondering: {if x_value == value} x {endif x_value}  (Read 4303 times)

0 Members and 1 Guest are viewing this topic.

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Wondering: {if x_value == value} x {endif x_value}
« 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?



Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Wondering: {if x_value == value} x {endif x_value}
« Reply #1 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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: Wondering: {if x_value == value} x {endif x_value}
« Reply #2 on: October 29, 2011, 10:43:18 PM »
Great, thanks, that will help me ;)