Announcement

Collapse
No announcement yet.

Successfully using PHP in a condition

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Successfully using PHP in a condition

    Has anyone managed to do this? The main help says it's possible (see the bottom of the Using PHP topic. Actinic says no with a nice big crash dump whenever I try it, even with the simplest of PHP code.

    #2
    Why not show your code and see if anyone can spot a mistake.

    Mike
    -----------------------------------------

    First Tackle - Fly Fishing and Game Angling

    -----------------------------------------

    Comment


      #3
      It was more of a general question really. My though process:
      1. The example in the help doesn't work.
      2. There's no UI in the condition editor to create the blocks as detailed by the help.
      3. Quick survey reveals nobody is using the feature.

      == probably broken in V9 == don't waste any more time pursuing the problem.

      Anyway, it's the code at the bottom of the help topic I mentioned, being pasted into Standard Layout Using CSS. Even doing something as innocuous as
      Code:
      <actinic:block php="true">1==1</actinic:block>
      crashes. Also bad
      Code:
      <actinic:block php="true" selectable="false">1</actinic:block>=1
      And clutching at straws, I've tried adding the selectable attribute thus:
      Code:
      <actinic:block php="true" selectable="false">1==1</actinic:block>
      Also no.

      Comment


        #4
        Sod it. Gave up, created a new layout with the content I needed, did the whole block in php and echoed the new layout instead. No crashes.

        Comment


          #5
          I'd add encoding="perl"

          Comment


            #6
            Yes! Err, no. Another crash dump to add to the collection!

            I've got the page output I need now from my alternate method. I don't really care that it's a bit mess, I just want to finish the site and stop using this tool as soon as possible.

            Comment


              #7
              Not really sure what you're upto... but post 15 of this thread may help:

              http://community.actinic.com/showthread.php?t=30805

              You have to copy/paste and then tinker :-)

              Comment


                #8
                first of all, your php is wrong.

                in php, you need to use if.

                PHP Code:
                <actinic:block php="true" selectable="false">
                if(
                1==1) {
                </
                actinic:block>

                MyActinicVariable

                <actinic:block php="true" selectable="false">
                }
                </
                actinic:block
                btw: untested, but this is how it SHOULD work.

                Comment


                  #9
                  althout a good example, please ignore that last post. it was out of context.

                  i failed to see that you were using actinics built in php conditioning.

                  Comment


                    #10
                    Originally posted by gabrielcrowe View Post
                    btw: untested, but this is how it SHOULD work.
                    Indeed it should: asp works this way, as, I'd imagine, does php. Unfortunately, Actinic doesn't: parse error in main on line 3. Move the closing brace into the same block as the opening one and it's fine.

                    @bentleybloke
                    Out of curiosity I tried the suggested code and it works fine with strings but not integers. Try the following and you'll see what I mean:
                    Code:
                    <actinic:block php="true" >
                    	$itemno = 0;
                    	$test = 'bath';
                    </actinic:block>
                    <actinic:block if="%24itemno%3d%3d0" >
                    	$itemno == 0<br>
                    </actinic:block>
                    <actinic:block if="%24test%20%3d%3d%3d%20%27bath%27" >
                    	$test === 'bath'<br>
                    </actinic:block>

                    Comment


                      #11
                      PHP variables in if statements is a nightmare. The example you've posted above doesn't work for strings either.

                      If you change

                      $test = 'bath';

                      to

                      $test = 'XXX';

                      the comparison seems to return true.

                      It would seem that only constants, php intrinsic functions and Variables work properly.
                      Norman - www.drillpine.biz
                      Edinburgh, U K / Bitez, Turkey

                      Comment


                        #12
                        Hahahaha. </hysterical> It doesn't do that here. Perhaps it's a difference between 8 and 9. Either way, it's not a feature I'd care to rely on.

                        This all makes it a complete bugger to get data back out from a php statement Your only option is an echo, which stops you from writing elegant presentational markup.

                        Comment


                          #13
                          Originally posted by simonc View Post
                          it's not a feature I'd care to rely on.
                          me too. its terrifying, the differences in the various versions of actinic.

                          Perhaps we need some sort of testing code that we should run on each version to see the results?

                          Comment


                            #14
                            I tend to use pure PHP and HEREDOC syntax.

                            E.g.
                            Code:
                            <actinic:block php="true">
                            if ( $variable == <actinic:variable name="AnotherVariable" /> )
                            $html = <<<ENDOFCODE
                            miscellaneous layouts here
                            ENDOFCODE;
                            echo $html;
                            </actinic:block>
                            However there's a slight risk that something within the layouts might be interpreted as PHP variables ( e.g. $something ).

                            Of course what I'd really like is a reliable way of using pre defined PHP variables in a blockif.
                            Norman - www.drillpine.biz
                            Edinburgh, U K / Bitez, Turkey

                            Comment


                              #15
                              Nice tip. I wasn't aware of that string syntax despite coming from a C# background where there's a similar @"...." syntax.

                              Comment

                              Working...
                              X