Are PHP Snippets working?


#1

I have created a PHP page and added a HTML snippet bric with the following code;

<?php

echo "Some text!";

?>

Preview in browser shows a blank page. Same result on the webpage arina.biz/phptest.php
Am I doing something basically wrong or is this feature broken. thanks - much appreciated of any feedback.


#2

Hi @AussieJohn

Yes that’s correct. It appears that the php code is being commented out in the code.

@Norm Is there a different approach to add php code ? Or a way to disable the commenting out of the php code?

Thanks,
Bill
BricsDesign


#3

Thanks Bill I thought I was going mad


#4

You can’t preview php with the Blocs preview in browser, it’s pretty basic and does not run a local server or php so it’s basically not rendering it. Use MAMP or some other tool to setup a local php server and then load your page via that local host.

I’m hoping to bring php previewing in the future.


#5

Thanks Norm - I have the page running live on my web server ( which runs php) and all I get is a blank page ( plus my header/footer). Arina.biz/phptest

Im afraid I dont understand your other instructions
cheers John


#6

try removing the returns, your source looks like its exporting as phpEcho


#7
<?php
echo 'some text!';
?>

Hi Norm
This is the actual text of the PHP. Are you able to confirm if the Snippet is working?


#8

your PHP works:


I cut and pasted from above to an HTML widget.
are you sure your published file is here: http://arina.biz/phptest

Do you have an index.html in that directory as well as the index.php?


#9

Well that is encouraging that it is working ( at your end) - it is definitely published at https://arina.biz/phptest
The site only has an index.html - no index.php
So just to backup a bit.

  1. My page is set to PHP
  2. I have added an HTML widget bric
  3. I have added the code ( as above)
  4. Published
    have I missed something?

#10

Did you set the page suffix to php in page settings?


#11

I did the same thing.

  • I put a html widget on the page
  • Changed page to PHP
  • Exported the site

Are you sure you’re publishing the site? Have you tried changing something else on the page (add a heading above the html)?


#12

This is frustrating. I have looked in the actual php file there is an error in the conversion as there is no space between php and echo. If I manually add one the page works. I should add the whole of the file was expressed in a single line.

<?phpecho 'some text!';?><p>A PHP snippet should be visible above</p><

The current webpage has the error corrected.
I certainly have the page set to php (as it wouldn’t generate the php file otherwise). I have also deleted the bloc and re-added a new one and the html widget.


#13

@AussieJohn

Yep, it looks like autominimize feature has removed all spaces & maybe even a return.

Just to verify did you type the first line as ‘<?php’ & then hit return? & then other code on next lines…
I don’t think minimize will remove returns, which would maybe fix the problem.
Let us know.

Bill
BricsDesign


#14

@Bill turning off minify HTML seems to get it working
@norm sounds like a bug
Thanks


#15

Blocs 2.5.3 beta build 2 will include a fix for this so minifying wont break the php.