@include & disappearing PHP code?

I am trying to use the @include function in my DevPack index.php file. :thinking:

In the documentation, it says @include(“hello”) which looks in the include folder for hello.html. I was trying to include layouts.php and for that file to include several svg files e.g. svg_1.html via @include(“svg_1”).

Anyway, didn’t work but more concerning was that none of the PHP code (via a pagestart portal) was output on Preview or Publishing, just the HTML. It took me a while to realise that the issue was triggered by use of @include. I had to remove the include folder in the DevPack and quit elements and restart it for the php code to reappear.

So the questions are:

  1. Is including PHP code supported?
  2. Is nesting includes supported?

Of course the above might be related to the transcribing / corruption of the output PHP code issue? :thinking:

OK, here’s a bit more detail on the issue. :slightly_smiling_face:

It seems that just having the include folder include in the templates folder with only html files in it (no PHP files) and no @include statement in index.php causes the PHP code (in the startpage portal) not to be output by Elements to either Preview or Published.

To recover, I have to delete the include folder in the DevPack and then close Elements down, then restart it and open the Elements project, then force an update on the DevPack by just saving index.php (so the Component icon) flashes in Elements and then re-publish and then the PHP code is back.

Workaround for the moment is to embed everything in the index.php source. :slight_smile:

Hi @tpbradley, Is this one fixed as well as part of the PHP transcribing fix or is it a separate issue?

Yes it’s possible. I’m having a little trouble following exactly what you’re doing here. However, I’ve tested a few things and can verify the following.

Yes, you can have php files in the component templates/include directory.

Yes, you can nest an include within another include and this also supports @portal() statements.

Hi @tpbradley - This is now working as you outlined above. Many thanks. :+1:

1 Like