In the past we could use url() in our themes to get the absolute url. Or absolute base url.

This patch re-adds that "feature", by making $base_url available to all parts of phptemplate templates.

Very simple. But a great benefit for themers. For me, this is a must have, when making a a theme. Esp. since we no longer have th base url.

In any case, will it make upgrading themes to versions without BASE tags a lot easier.

Comments

rkerr’s picture

This is must-have functionality for themes!
+1

Although I cannot confirm that this particular patch applies yet.

morbus iff’s picture

Note that url() still works just fine by passing the $absolute parameter.

guckie’s picture

StatusFileSize
new30.45 KB

Could someone please confirm for me whether this issue is what causes the issues shown in the attached screenshot of the administer log on my test site?

Theoretically, should the base url patch clear this up?

Bèr Kessels’s picture

you write a patch about base_url and retrieving that in the theme. you then say that the patch will make "upgrading themes ... without BASE tags a lot easier" when, in fact, if a themer wants to use base_url, then the HTML tag would have nothing to do with it whatsoever.

I do not really understand the difference. But still, this seems to be a more correct description.

Also note that we can use url(NULL, NULL, NULL, TRUE), whichs is a lot more code then a simple $base_url in your theme.

Bèr Kessels’s picture

Gucky, with the attached patch, you can re-add a base tag in your page.tpl.php which will most probably fix your issue.

But I am not hundred percent sure. There are other reasons thinkable that could cause your issue.

Bèr Kessels’s picture

StatusFileSize
new1.16 KB

This is he same patch, bu now from the drupal root. sorry for that.

guckie’s picture

StatusFileSize
new3.64 KB

Thank you very much for your reply, Bèr! Your $base_url patch (and adding the tag to page.tpl.php) did indeed clear up almost all of the 'page not found' warnings I was getting.

The only ones remaining seem to be coming from the store module (screenshot attached), so I'll try to hunt down the cause of that.

I appreciate your help!

markus_petrux’s picture

Maybe, if there was a function to retrieve the base_url? ...this was suggested by Dries here.

guckie’s picture

You are awesome! That is exactly the issue - thanks for pointing that out to me =)

Kobus’s picture

This works (#6) indeed!

Thanks, Bèr!

Regards,

Kobus

robertdouglass’s picture

I will be using this patch on all my 4.7 installations. This is a usability issue. If we break backwards compatibiity of all themes when we have such an elegant soultion available, we're foolish. 1++ for this patch.

Steven’s picture

Status: Needs review » Closed (works as designed)

What's the fuss? Upgrading a theme takes a minimal amount of time, and themes break anyway. The only thing that needs changing for this are files referenced directly from the templates: <img>, <link> and external <script> and <style> tags. Anything in external .css files is relative to the file itself and doesn't need changing.

Takes 2 minutes to solve with find-and-replace in any text editor.

Bèr Kessels’s picture

Title: re-add a possibility to retrieve base_url » Introduce an API to retreive the base url.
Status: Closed (works as designed) » Active

We get 8 +1s for the addition of a USEFULL API. And it gets wontfoixed because it is easy to solve by replacing stuff.

I am getting absolutely mad about this attitute. Why am I not allowed to choose te preferred way of dealing with MY themes.
Who gives Steven the credentials to choose whether or not I can use base url?

If someone gives me agood reason why:
* Having an API to retreive the base url, is cruft
* Having an API to re-add the base url is not wanted,

then its fine. Then close this.

This patch adds a simple API to retreive the URL of your site in your theme. Nothing more. nothing less. And certainly no fuss.

robertdouglass’s picture

I still support this patch. I would rather have $base_url available as a variable in my theme than have to call url(). And there are times in themes when you want a fully qualified URL. I don't see what the possible arguments against this patch could be. There is no performance hit that could possibly be measured, it doesn't make anything harder, it makes several things easier, and several developers of good repute have said that they would like to see it in. Perhaps the decision to close the issue could be reconsidered?

chx’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new935 bytes

Steven, for heaven's sake this is a one liner and indeed very useful.

Bèr Kessels’s picture

@steven. If, for example, you feel an urge to fix the bluebeach search bug, you will find this variable in the phptemplate very usefull.

Steven’s picture

Please, give concrete examples where this is useful.

base_path() is the preferred prefix for URLs for theme include paths, as documented on the theme upgrading guide. It generates a short relative URL which the browser will resolve correctly. You don't want bulky absolute URLs for stuff which is included on every single page.

If you /do/ need the full base URL, then IMO you are doing something exotic and weird. Still, you are free to use the global $base_url, either through the global statement or the $GLOBALS[] array. You don't need url(). Why do we need a special PHPTemplate variable for this? It is hardly going to matter.

PS: Bluebeach search works perfectly for me. If there are issues, please file an infrastructure bug. I'm not psychic.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

so.