I discovered this while playing with the k4 theme, which displays an "edit" icon near every listed teaser and every full node. There is this code in node.tpl.php:

src="<?php print $directory ?>/images/pencil.png"

where $directory is supposed to get the current theme's path 'themes/k2'

My 'node/3' was aliased as 'news/announcent-2006-5-25' When I view this node as a teaser on the front page everything works ok. But when I go to the node's page the image is not found because the $directory variable becomes 'news/themes/k2'

There was another problem with the $node_url variable in that theme, which was also confused by the alias, but I considered that one "by design" and replaced it with "$base_path . '/node/' . $node->nid".

The $directory variable, however, should not be affected by aliases because its job is to get the theme's path.

Comments

cog.rusty’s picture

A second thought about the second problem which I considered a non-issue.

The problem was that "news/announcement-2006-5-25/edit" does not work and you need to use "node/3/edit" to edit the node. My second thought was that maybe it should be made to work? It does not seem impossible, since the alias maps uniquely to the node.

cog.rusty’s picture

Further fiddling showed that the problem of the $directory variable amounts to a missing leading slash.

Shouldn't the front slash be included in $directory? I can't think of a use case where it is not required.

cog.rusty’s picture

Bump.

Let me describe this better. There is a problem with the $directory phptemplate variable which is supposed to return a theme's path.

- In a teaser listing page, the $directory path resolves to '/themes/themename' (right).
- In a node page, the $directory path resolves to '/node/themes/themename' (wrong).
- In any page with an alias, the $directory path resolves to '/alias-path/themes/themename' (wrong).

The cause of this problem is that $directory contains the *relative* path 'themes/themename', and it is resolved depending on the current page. A workaround for the theme developer is to always add a forward slash in front of $directory, and the questions is: Is there any reason that the forward slash is not already included in the variable?

cog.rusty’s picture

I just realised that the problem appears only when you use clean URLs, because without them 'node' or aliases are not included in the page's path.

Adding a slash would fix the theme if clean URLs are used, but would break it if they are not used.

cog.rusty’s picture

Title: Theme variable $directory includes alias path when viewing an aliased node » Theme variable $directory resolves to aliased path when viewing an aliased node with cleanURLs
cog.rusty’s picture

Status: Active » Closed (fixed)

I'll assume that the $directory phptemplate variable is intended to be used always together with $base_path and a slash. So. I am closing this as "by design".