Php in content section?

I have a sub menu in the content section like documentation under support - When I enter a litte php-script to highlight the selected submenu this doesn’t work and the site will not show up at all. Any suggestions?

menu-item like

> <li><a class="<?php isactive($path,''); ?>" href="<?php echo $path; ?>/home">Start</a></li>


<?php function isactive($path, $url) { $req = $_SERVER['REQUEST_URI']; $req = "/".str_replace($path,"",$req); if (strlen($req)<=2 and strlen($url)<=1) { echo 'active'; } else { if (strpos($req,$url)!==false) {echo 'active';} else {echo 'inactive';}; }; } ?>

Hi @abirkner,

what file, complete of path, are you editing?
Do you have display_errors on?

Try making it valid PHP code by adding extra brackets to the first if statement; needed to make the and work.

if ( ( strlen($req) <= 2 ) and ( strlen($url) <= 1 ) )

Thx for the help… but still I can’t use the code in the content section.

  1. I have a top navigation, there the php script works fine!
  2. I added the brackets - thx for this
  3. I have a block containing the navigation. On the top I reference with <?php include("content/blocks/navigation/oben.txt"); ?>
  4. In the content section I reference with: {{block:navigation/produkte}} that makes the error, when I add the php function in the navigation like: <li><a class="<?php isactive($path,''); ?>" href="<?php echo $path; ?>/produkte/webhosting">Webhosting</a></li>

As the result of the above code in the navigation (in content section) the page will look like this:

Sorry @abirkner, I have no clear your files organization. Tell me if I have understood

you have a Pulse page calling
    {{block:navigation/produkte}} calling in turn

Also, you have the script in oben.txt and
you call isactive($path,’’) in that Pulse page.

Is it right?

No, sorry...

  1. php is a block but inserted via include
  2. files
    -blocks/navigation/oben.txt - means menu on the top
    -blocks/navigation/produkte - meaens menu at the left

in layout.php
<?php include("content/blocks/navigation/php.txt"); ?>
<?php include("content/blocks/navigation/oben.txt"); ?>

sample page:


  1. you have defined isactive() in php.txt
  2. calling isactive() from oben.txt is OK
  3. calling isactive() from {{block:navigation/produkte}} gives the error


If yes I guess you have an error because {{block:navigation/produkte}} doesn’t see the function isactive()
I am not sure, if you want, try this:

copy the definition of isactive() on top of produkte.txt

what happen?

Hi Tarqez,
well here ist a picture of my layout.php.
So the function should be available...
I tried copying the php-script. Did not work either!

@abirkner, why don’t you try to turn error messages on?

Adding these lines, always on top of produkte.txt should turn them on

ini_set(‘display_startup_errors’, 1);
ini_set(‘display_errors’, 1);

let me know

I tested your php-settings…

here is the result in the browser!

<div id="nav-left">
		<li><a class="

That’s the new page :slight_smile:

If i delete my php-code, the page will show up normaly…
class="<?php isactive($path,''); ?>" <-- deleted in
<li><a class="<?php isactive($path,''); ?> href="<?php echo $path; ?>/produkte/webhosting">Webhosting</a></li>

So, problem solved or not yet?

I see one thing here, my include has a leading /

<?php include("/content/blocks/nav.txt"); ?>

Not solved, only the applied page was loaded… what is nearly nothing!

  • no error message, but turned on – with your settings!

the navigation shows up… the / seems not to be the problem!

I am sorry, it is hard to understand without files under my nose.

I just tested my homepage without pulsecms. I copied all blocks in the layout.php. After that I tested the page. No error, the page shows up. :slight_smile: It seems that that in the content section in pulsecms it is not a good idea to have a php-script! :frowning:

I suppose that for content section you mean the folder content.
Inside that folder, I would tend to insert PHP code only in super-blocks.
No in blocks, no in pages and no in blog posts.

In my opinion, this is a good practice.

Why is your php.txt included outside the HEAD-section and also outside the BODY-section?
Have your tried applying this to the default ACME site?
If it does not work in there, you can simply share the files.