Welcome to Geeklog Friday, October 20 2017 @ 08:17 am EDT


Status: offline

Chrispcritters

Forum User
Chatty
Registered: 11/05/2005
Posts: 49
Location:Tustin, CA
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?

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
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.

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/2005
Posts: 985
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.

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
btw, I justed tested my solution and it works fine.

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/2005
Posts: 985
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.

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
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.

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/2005
Posts: 985
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.

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
yes of course you're right. :shakehands: it was just off the top of my head.

All times are EDT. The time is now 08:17 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content