HOWTO: Display some arbitrary HTML on a specific page based on the URL you are on

This snippet shows you how to insert simple "if" statements in your theme to display html or any other block of code based on the URL you are on. In the example it shows you how to display a block of text before printing out a taxonomy node listing.

1) open up page.tpl.php in your phptemplate theme.
2) Right above where it starts printing out your main content in your theme (usually starts with printing
menu tabs) you can insert some logic.
3) you can use some logic to figure out what page you are on. For instance for the URL:

http://www.example.com/taxonomy/term/10

arg(0) returns 'taxonomy'
arg(1) returns 'term'
arg(2) returns '10'

4) If you want to display some html if you are on that
page, you put in some logic in your theme file (page.tpl.php).


<?php if(arg(0)=='taxonomy' & arg(1)=='term' & arg(2)== '10'): ?>
  This is where you put the html you want to print out
  on this page! It won't print this if we aren't on this
  page.

<?php endif; ?>

MAIN CONTENT

That's all the php you have to type. The logic says, "If we are on the taxonomy/term/10 page, let's print
this html code. Otherwise let's skip it and continue to the main content." You can see that this is

Inserting HTML into node titles

Drupal strips all HTML from node titles when they're displayed to prevent XSS exploits. However, there are some cases where inline HTML elements are needed, such as when titles contain scientific names.

To work around this, we will use pseudotags like [i] and [/i] which Drupal will safely translate into real HTML tags when the page is displayed.

We need two new functions (please note that Drupal best practices are to include functions in template.php or a custom module; logic should not be placed in *.tpl.php).

function bb2html($text) {
  $bbcode = array(
                  "[strong]", "[/strong]",
                  "[b]",  "[/b]",
                  "[u]",  "[/u]",
                  "[i]",  "[/i]",
                  "[em]", "[/em]"
                );
  $htmlcode = array(
                "<strong>", "</strong>",
                "<strong>", "</strong>",
                "<u>", "</u>",
                "<em>", "</em>",
                "<em>", "</em>"
              );
  return str_replace($bbcode, $htmlcode, $text);
}

function bb_strip($text) {
  $bbcode = array(
                  "[strong]", "[/strong]",
                  "[b]",  "[/b]",
                  "[u]",  "[/u]",
                  "[i]",  "[/i]",
                  "[em]", "[/em]"
                );
  return str_replace($bbcode, '', $text);
}

Create a forum

Users can post topics to forums. Forums can appear below other forums in a hierarchy, or can appear in containers.

Mass URL aliasing

Drupal also comes with user defined mass URL aliasing capabilities. You might like to see completely different URLs used by Drupal, or even URLs translated to the visitors' native language, in which case this feature is handy. Only an administrator with access to the website source code can set up this kind of aliases. You can define a function somewhere in your code (even in settings.php), following this example:

Create forum containers

Containers are 'parents' for forums (discussion boards); they are used to group forums. Users cannot post topics to containers; users post to the forums in the container(s). A site with only a few forum discussion boards may not need any containers.

Pages

Subscribe with RSS Subscribe to RSS - Drupal 6.x