Writing PHP code inside superblocks

In Pulse 4 it was possible to write PH code inside superblocks.

Today I tried this with Pulse 5 but that does not work, it just prints out the whole php command.

So PHP doesn’t work in superblocks anymore?

That depends!

HTML + JS work fully. As for PHP…

In reality it was a potentially dangerous security hole so we added some code to eval the PHP in a sb_block and capture the output to make P5 much more secure.

Not sure what PHP code you are trying to insert but here a few solutions you could use:

  • (recommended) Make a Tag/Plugin and just use the custom {{tag}} to embed it in that Block or your page, and add any variables you need to the tag
  • Use a PHP include into that Block or Page
  • Rename the Block from .txt to .php

Good luck with the project :slight_smile:

2 Likes

Okay, I understand. I just wanted to set the CSS class for navigation.
Like this:

<a href="/about" <?php if(basename($_SERVER['REQUEST_URI'])=="about"){echo "class='active'";}?>>ABOUT</a>

2 Likes

This setting of active should be a standard thing. @pulsecms we should add that into the standard nav tag. Also good for further RW nav integration.

1 Like

Thanks for the info.

I have used the “Tag/Plugin” way, simple but effective.

My simple solution, if someone needs it too:
link-active.php inside /inc/tags

<?php

$classname  = $GLOBALS['tag_var1'];
$pagename   = $GLOBALS['tag_var2'];

if (basename($_SERVER['REQUEST_URI'])==$pagename)
    {
        echo "class=\"" . $classname . "\"";
    }

?>

My navigation looks like this:

<nav id="primary-menu" class="style-3">
<ul>
  <li {{link-active:current:Home}}>
    <a href="Home">
      <div>Home</div>
    </a>
  </li>
  <li {{link-active:current:Ueberuns}}>
    <a href="Ueberuns">
      <div>Über Uns</div>
    </a>
  </li>
  <li {{link-active:current:Produkte}}>
    <a href="Produkte">
      <div>Produkte</div>
    </a>
  </li> . . .

Where “current” is my active class and the second parameter the pagename of course.

2 Likes

Thanks Oliver. Did you perform test with a 2nd level navigation or a blog page?

1 Like

Looks great and nice solution @Oliver :slight_smile:

Active links in the front end is already included in navigation since P5…

1 Like

Honestly, I didn’t test that, it was more like a rush job.
But I would say that it just doesn’t work because the pagename does not match the first level.
I have to try that out.

This topic was automatically closed after 5 days. New replies are no longer allowed.