Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted May 25, 20222 yr Hi all, I've successfully created a custom block containing some php which just echo's text to the page (as a simple test). But I get an error on save if I do anything other than wrap my custom php inside a function, like so: function myTest() { echo 'testing'; } How to I run my function? If I just include myTest() in the page source I get an error.
May 25, 20222 yr Community Expert If you are adding exactly what you put second there, you are missing a semicolon at the end.
May 26, 20222 yr Author Thanks Marc. Unfortunately I can no longer edit the original post but that was just my example. Can you please confirm for me how this is supposed to work, because I can't find it in the documentation. Is it a requirement that php code be encapsulated in a function, and then the function must be called (the only non-functionised code) from a single line as I have shown above (with semicolon)? I can't get anything to generate some output, even though the block editor is no longer balking at my php code.
May 26, 20222 yr Community Expert Solution As long as the semicolon is there that code works just fine inside a custom PHP block. I just tested myself by copy pasting your code (adding the semicolon) in a block. Then I added the block to a page. Maybe you have more code in your block other than the one you posted in the first post? And no, there is no need to even use a function. You can just input your PHP code inside the block without it. A custom PHP block with the code below prints the same output as your code above: echo 'testing'; Edited May 26, 20222 yr by teraßyte
May 30, 20222 yr Author I see thanks guys. I don't know what is going on with my cloud setup but this code wasn't working on Friday, and I refreshed today and it starts working. Must have been a cache issue somewhere, but thanks for the help.