Skip to main content

Author Topic: Can I have other PHP code on a page served though XT-CMS?

p
  • *
  • Newbie
  • Posts: 6
I have written a small piece of PHP and inserted it into a place-holder as Body HTML on my home/index page. When I publish my site directly to the web and then change the name of the page on the server from index.htm to index.php, the page woks well. However, when I publish it as a template to the CMS directory the CMS aspeccts of the page work fine, but my PHP is not understood or interpreted (and nothing appears on the screen, where I expected my output to be).

Am I trying to do the impossible by having some non-CMS PHP code on a page served by XT-CMS, or is there some trick that I have missed?

Thanks
Peter
  • IP logged

  • *****
  • Administrator
  • Full Member
  • Posts: 232
    • XT CMS
There could be some conflict happening between the two or the import template process could be breaking your php code.

In general it should work and you can do a quick test by just putting some simple php code in your template.

Code: [Select]
<?php echo "testing my php code"?>
See if you can get this working first. It should display the text on the page and you can search in the pages generated html source code for it too.

Also if you go to cms/data/templates this is where the imported page templates are stored that the cms will use for outputting the pages, you can check the source code of these and see if your php is present and correct or if it has been broken by the import process.

You could also try saving your php code in it's own dedicated include file eg. "my.php" place the file in the includes folder in your theme then in the page template instead of pasting all the php code just use the special tag {inc_my.php}

By the way no need to rename page template files to php for the cms as it will change them to php automatically. In fact check that you don't have two files with the same name but with different extensions eg. mypage.htm and mypage.php as the cms will only use one of them and it might not be the one you expect.
  • IP logged
« Last Edit: October 26, 2015, 10:29:50 AM by xtom »

p
  • *
  • Newbie
  • Posts: 6
Thank you for this really helpful advice. I have now got it working fine - the main problem was my simple misunderstanding about file locations... My PHP code takes inputs from a separate text file and uses this to display messages on the screen. For simplicity, I put the text file in the same location as the HTML file. I therefore thought that since I upload the files to the CMS themes folder, I should also put my text file in this location. I can now clearly see that this is wrong and that the text file needs to go in the root directory of the website.

I am really impressed by XT-CMS now that I am starting to get to grips with it!

Peter
  • IP logged