Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Blog

Conditional block using PHP

Jimi Wikman


I have been struggling a bit about the header blocks since there are some template differences between pages, databases and applications. Now I think i have a solution for it however as I have tested to use raw PHP in the blocks. This allow me to display content based on the URL, which seem to be working fine.

Adding a bit of PHP for the blocks was not really very difficult. There are plenty of examples online and I started with a simple url match using the $_SERVER['REQUEST_URI'] function.

$host = $_SERVER['REQUEST_URI'];
if($host == '/projects/') 
    echo ('Whatever you want in here');

    echo('Whatever you want in here or leave blank to show nothing');

I did however need to change this a bit since there are pagination and I want to have the same content on all pages for the pagination. It's easy since there is just a number that is added to the URL for each page. I should make a proper solution for this, but for now I just added the pagination pages in an array. I also tested to include other blocks, which worked fine. This should make things a bit more dynamic if I want that.

$host = $_SERVER['REQUEST_URI'];
if(in_array($host ,array(
    echo ('whatever you want here');
elseif ($host == '/projects/projektledare/') {




Overall this solve the immediate issue and I can proceed as planned. I just want to make sure I can get the pagination working without manually adding all the pages. That is something to look for tomorrow however as today I am going to sleep and enjoy the progress so far.


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Who's Online   0 Members, 0 Anonymous, 22 Guests (See full list)

    There are no registered users currently online

  • Create New...