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

Conditional block using PHP

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.

Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Who's Online   0 Members, 0 Anonymous, 7 Guests (See full list)

    There are no registered users currently online

  • Create New...