Score:1

How do I parse a path alias?

xk flag

I have the following code in my page.tpl.php file.

<?php $path = drupal_get_path_alias($_GET['q']); ?>
<?php if ($path == 'about-us'): ?>
  <div class="container">
    <h1> about us!!!!</h1> 
  </div>
<?php endif; ?> 

This works for /about-us, but not for /about-us/abc.

What code would work for all the paths under /about-us?

I've messed around with arg(), but I ended up with a page error.

berliner avatar
bd flag
This seems to be a question about PHP and not specifically about Drupal. Have a look at the available string functions in PHP: https://www.php.net/manual/en/ref.strings.php
Score:1
cn flag
// Retrieve an array that contains the path pieces.
$path_args = arg();

// Check if the current page is the page you're looking for.
if ($path_args[0] == 'about-us') {
  // Your code.
}
leymannx avatar
ne flag
You mean `$path_args[0]`?
cn flag
@leymannx yes, thanks
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.