1

I have a content type which has an automatic path alias to latest-news/[title] (e.g. latest-news/example-news-title).

I need to get the first part of the path alias in my page.tpl.php file, but when I use arg(0) I am given node and not latest-news.

How can I get the first part of an aliases URL in a page template?

1
  • Templating by aliases instead of templating by what you want to template seems risky. Why do you need that? why don't you template by content type?
    – Mołot
    Nov 11, 2014 at 10:48

1 Answer 1

2

You can use function drupal_get_path_alias() to get the path alias, then strstr() to get the first component of the path, like so.

echo strstr(drupal_get_path_alias(), '/', TRUE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.