Jump to content


Photo

Echoing UrlSegment?

urlSegment

  • Please log in to reply
2 replies to this topic

#1 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 788 posts
  • 205

  • LocationMidlands, UK

Posted 19 April 2012 - 04:48 AM

Is there a way to echo a URL segment for example to use in the <title> tag?

Eg:

<title><?php echo $page->title; ?> | <?php echo $input->urlSegment(2); ?></title>

The above code was my stab at it but I'm not sure if segments can be called in this way?

Sorry, should point out that this is within a header.inc template

Edited by onjegolders, 19 April 2012 - 04:49 AM.


#2 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 788 posts
  • 205

  • LocationMidlands, UK

Posted 19 April 2012 - 05:12 AM

For my page titles, I have found another way of doing it with the following code:

<title>Site Name | <?php if ($page->rootParent->title != $page->title) {echo $page->rootParent->title . " | ";} ?><?php echo $page->title; ?></title>

Would still be interested to know if you can echo or use urlSegments in if statements though.

Thanks

#3 diogo

diogo

    Hero Member

  • Moderators
  • 1,973 posts
  • 1059

  • LocationPorto, Portugal

Posted 19 April 2012 - 06:53 AM

You can do what you want like this:
echo '<title>' . ($input->urlSegment2 ? $input->urlSegment2 : $page->title) . '</title>';






Also tagged with one or more of these keywords: urlSegment

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users