Subject: $pagetitle in a block

Posted on: 30/07/07 12:25pm
By: Chrispcritters

I'm trying to pull the $pagetitle value into a block, but it's just bringing in the site name and does not include the staticpages title. Anyone know how to do this?

Re: $pagetitle in a block

Posted on: 06/08/07 03:05pm
By: machinari

write a php block function that returns $_CONF[pagetitle] as well as your block content. store it in your lib-custom according to the instructions for creating php blocks.
for example:
PHP Formatted Code

function phpblock_SPpagetitle() {
  global $_CONF;
  $retval = '';
  $retval .= $_CONF['pagetitle'];
  $retval .= 'rest of block content';
  return $retval;
}
 

I dunno but I don't see any reason why that wouldn't work.

Re: $pagetitle in a block

Posted on: 06/08/07 03:37pm
By: jmucchiello

You need two functions CUSTOM_templatesetvars (or if you are in a plugin use plugin_templatesetvars_$plugin) and your phpblock.

PHP Formatted Code

$current_pagetitle = '';

function CUSTOM_templatesetvars($templatename, $template)
{
    global $current_pagetitle;
    if ($templatename == 'header') {
        $current_pagetitle = $template->get_var('page_title');
    }
}

function phpblock_whatever()
{
     global $current_pagetitle;
     $display = "The current page title is $current_pagetitle";
     return $display;
}


That's entirely untested but I think it does it. I'll try it myself later if I get the chance.

Re: $pagetitle in a block

Posted on: 06/08/07 04:14pm
By: machinari

btw, I justed tested my solution and it works fine.

Re: $pagetitle in a block

Posted on: 06/08/07 05:52pm
By: jmucchiello

Mine works in right blocks, not left blocks. I thought the templatesetvars was called before blocks were done but it happens in the opposite order.

Machinari - Yours only works on staticpages (because the staticpage code modifies $_CONF['pagetitle'] directly). That's what the OP wants but a generic pagetitle block only works with my code and only on a right block.

Re: $pagetitle in a block

Posted on: 06/08/07 08:55pm
By: machinari

Quote by: jmucchiello

Machinari - Yours only works on staticpages

Yup. that's what he wanted. I presumed that he has a plan for checking the current page in order to ensure that the block returns empty when he's not on a staticpage.

and chrisp, if you haven't thought of that then here's where your start. Here are two options for your phpblock. both work and will only return stuff on staticpages.
PHP Formatted Code

/* I want this block to return something on staticpages only. */
function phpblock_SPpagetitle() {
  global $_CONF;
  $retval = '';
  $thisurl = COM_getCurrentURL();
  if (eregi('staticpage', $thisurl)){
    $retval = $_CONF['pagetitle'];
  }
  return $retval;
}

/* I want this block to return something on the specified staticpages only. */
function phpblock_SPpagetitle() {
  global $_CONF;
  $retval = '';
  $thisurl = COM_getCurrentURL();
  $pages = array('http://mypage1',
                            'http://mypage2',
                            'http://mypage3');
  if (in_array($thisurl, $pages){
    $retval = $_CONF['pagetitle'];
  }
  return $retval;
}
 
or something like that.

Re: $pagetitle in a block

Posted on: 06/08/07 11:22pm
By: jmucchiello

You should use (stristr($thisurl, 'staticpages'Wink !== false) rather than eregi. Without a regular expression there's no reason to use eregi. Also, there use to be a task to eliminate ereg* from Geeklog in favor of the preg* function since the preg* functions support unicode.

If you are on PHP5, use stripos in place of stristr as it doesn't return the unneeded string.

Re: $pagetitle in a block

Posted on: 07/08/07 12:52am
By: machinari

yes of course you're right. :shakehands: it was just off the top of my head.

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=77639