1
votes

So basically I am using a drupal multi-site. Structure is as follows:

mywebsite.com: -- public_html/sites/default/

sub.mywebsite.com: -- public_html/sites/sub.mywebsite.com/

Works just fine(via settings.php), but the problem comes when theming. In order to reference valid image files, I must use drupal_get_path('theme','mythemefolder') And due to having "pretty urls" activated, I must use the following code to reference the image files:

$uri=$_SERVER["REQUEST_URI"];
$path=drupal_get_path('theme','mythemefolder')."/";
$real_prefix=$base_path; // global from drupal, equates to "/" as drupal resides in public_html folder.
$count=substr_count($uri,"/");
for ($i=0;$i<$count;$i++) $real_prefix.="../";

In this way, I can do the following:

<script type="text/css">
#borderclass {
  background-image: url('<?= $real_prefix.$path.'images/a_border_image.png'; ?>');
  background-repeat: repeat-x;
  vertical-align: top;
}
</script>
<div class="borderclass" width="10px" height="10px"><!-- my image border div --></div>

It would be much preferable to not have to do this. And just simply reference the local site folder...

So that instead, I could write via PHP referenced above:

<div style="background-image: url('<?= $path ?>images/a_border_image.png');"></div>


The resulting html should instead appear inside View Source, as:

<div style="background-image: url('themes/mythemefolder/images/a_border_image.png');"></div>

and Not:

<div style="background-image: url('sites/sub.mywebsite.com/themes/mythemefolder/images/a_border_image.png');"></div>

Is it possible to configure my server to do such a thing? Basically, I'd rather not have my clients even know that the "sites" directory exists on the server when using their own domain or subdomain. Let alone the above presented theming issue.

1

1 Answers

0
votes

From what I understand what you are trying to understand, let me tell you that this is not how you usually deal with things.

A module does not need to look at the theme (except template files) folder to get anything. Logo, headers and other theme-related stuff can be stored in a theme's subfolder named "images" or anything else.

A theme folder will contain all template files (page template, html template, node template, etc) but a variable is ready for you if you want to get the theme's path.

url() in css, if the style is in a file, will be relative to the css file - not the current page. So that's where you can enter url('images/a_border_image.png') so it will be relative to the theme folder regardless of the theme's location. Browser is aware that the css file's location is sites/sub.mywebsite.com/themes/mythemefolder and your url() stuff in css will be relative to that folder.

However, in case you want to get the correct path (easily), do this:

<?php
$theme_path = drupal_get_path('theme','mythemefolder').'/';
$real_path = url($theme_path . 'images/images/a_border_image.png'); // 'sites/sub.mywebsite.com/themes/mythemefolder/images/a_border_image.png'
?>

url() will handle base path and all the substr stuff for you.