Announcement

Collapse
No announcement yet.

Using php in a BlockIf

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

    Using php in a BlockIf

    I want to be able to test the first two characters of the Product Reference in a BlockIf.

    I can extract the two characters easily using a little php but I can't get the php to run inside the BlockIf.

    Any ideas how to do this?

    #2
    Thinking aloud.

    Perhaps I could do the whole BlockIf function in php instead.

    Comment


      #3
      BlockIfs are already PHP. Try your code without any PHP tags. Variables are embedded with invisible double quotes. See some Advanced Guide articles for examples.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        No- still can't get it to accept it as a valid expression.

        This is what I currently have in the BlockIf:

        ($sProdRef = '<actinic:variable name="ProductReference" selectable="false" />';$sProdRef = substr($sProdRef, 0, 2);echo $sProdRef == "AG"

        Comment


          #5
          I also tried just using php instead and to echo the resultant code that is inside the BlockIf tags but it is a Layout and I can't get the php to echo a Layout only a variable or php result.

          Comment


            #6
            Way too much code. Try

            substr(<actinic:variablename="ProductReference" selectable="false" />, 0, 2) == "AG"

            Think of the entire expression as something that must evaluate to true/false.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Still sees it as an invalid expression

              Comment


                #8
                Try quotes around the variable. Travelling and using a Xoom so unable to test anything.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  This is a valid expression (with ' quotes) but does not seem to ever be true, although I know it should be:
                  substr('<actinic:variablename="ProductReference" selectable="false" />', 0, 2) == "AG"

                  Comment


                    #10
                    O.K. Found my laptop. This code works. Using SectionName so I can see the response on different Sections.
                    Code:
                    <actinic:block if="substr%28%3cactinic%3avariable%20name%3d%22SectionName%22%20%2f%3e,%200,%202%29%20%3d%3d%20%22BT%22" >
                    	FOUND IT
                    </actinic:block>
                    <actinic:block if="substr%28%3cactinic%3avariable%20name%3d%22SectionName%22%20%2f%3e,%200,%202%29%20%21%3d%20%22BT%22" >
                    	NOT FOUND
                    </actinic:block>
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      Excellent Norman - many many thanks for your efforts and solutions as ever!
                      I have just tried this and it works great with the ProductReference as well as I need it.

                      I think the issue may have been that the encoding and selectable need removing if inside the BlockIf - but not tested it fully.

                      Comment


                        #12
                        I would guess that the encoding is set automatically to Perl, selectable is set to off and variables are passed to PHP with single quotes around them.

                        So if you looked (with quotes) for "<actinic:variable name="ProductReference" />" == "AG"

                        you were probably testing "'AG'" == "AG"
                        Norman - www.drillpine.biz
                        Edinburgh, U K / Bitez, Turkey

                        Comment

                        Working...
                        X