0

What's the easiest way to access the HTTP host name inside an ExpressionEngine template (without resorting to using PHP in the template).

Has a plugin already been created to do this, or should I use some sort of global variable?

Bonus points if there is a way to access other HTTP server variables inside an ExpressionEngine template as well.

4

4 に答える 4

9

You can set the hostname as a global variable and use that. You can set the global variable in your config file with php, and then you will have access to it in the template.

Or you can use {path='site_index'}

$assign_to_config['global_vars']['global_var_name'] = 'Global var value';
于 2012-10-27T00:56:15.297 に答える
3

これには、サーバー変数 http://devot-ee.com/add-ons/server-variableというアドオンを使用できます。

{exp:server_var:server var="HTTP_HOST"}

他のサーバー変数も利用できます:http://php.net/manual/en/reserved.variables.server.php

于 2012-10-28T16:16:30.580 に答える
3

How about just using {site_url} which is a standard global variable?

If you want to assign a config variable then you could do:

$assign_to_config['global_vars']['gv_hostname'] = $_SERVER['HTTP_HOST']; 

and then within your template you could call it via {gv_hostname} of course this wouldn't add the http:// before the hostname.

于 2012-10-27T11:50:14.957 に答える
1

You could add the following code to your /system/expressionengine/config/config.php file

$assign_to_config['global_vars']['my_http_host'] = $_SERVER['HTTP_HOST'];

This could then be used in templates like so:

{my_http_host}

If you wanted the protocol ie. http if not https you could do this:

$assign_to_config['global_vars']['my_protocol'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';

This could then be used in template like so:

{my_protocol}

Here is a list of PHP Reserved Server Variables

于 2012-10-27T19:41:23.270 に答える