1

We are planning to use Domain Access to manage 5 different domains that will share content. The majority of our pages will be shared across all 5 domains and will look identical on each domain. Domain Access makes it trivial to handle this use case. However, on some of the pages, 95% of the content will be identical and 5% of the content will be dependent upon the domain that is serving the page.

One possible solution is to create a unique page for each domain and publish it to the appropriate domain. Although this works, it is difficult to maintain because we would need to maintain changes to the identical content across 5 unique pages.

Another option would be to embed PHP in the page, such as

shared content for all 5 sites here.

<?php if ($_SERVER['HTTP_HOST'] === 'domain1.example.com') { ?>

domain1 specific content here

<?php } else if ($_SERVER['HTTP_HOST'] === 'domain2.example.com') { ?>

domain2 specific content here

<?php } ?>

Again, this would work, but has several disadvantages. I am looking for a way to share the identical content across the domains and yet have site specific content within a page in a way that makes it feasible to maintain and easy for content editors (non-technical users) to edit. Does anyone have any suggestions?

0

The sites module has support for multiple domains and managing content across those domains.

https://www.drupal.org/project/sites

If you are using the same template file for the page where you are displaying your content, then you can implement the 'hook_site_access()' from the sites module in the template file, and gather the content you desire to display based on the domain name.

In addition, depending on the type of content you are displaying, you might be able to get away with simply using the Views or Context integration from the Sites module, rather than editing your template file manually.

Another option is to use Drupal's taxonomies to classify your content. Then, you could use any of the solutions above (custom code in page template, Views, or Context) to filter only the content which is categorized to be displayed on the domain you are on.

In any case, if you want two different versions of the same page to display on different domains, you will need two different nodes, and they will need to be classified accordingly. I'm not sure if there is any way around maintaining multiple nodes if the content varies by domain.

However, when the same node is to be displayed on multiple domains, this kind of architecture will allow you to display it only on a specific subset of domains you choose.

0

Using the Domain Access module, you can put this in your template.php file:

function YOURTHEMENAME_preprocess_page(&$vars) {
  global $_domain;
  $vars['current_domain'] = $_domain['domain_id'];
}

Once this is done, you'll have a variable you can use in your .tpl-files. The code above provides the domain's ID, which you can find in admin/structure/domain by hovering over the "edit domain" link.

You can use it like this:

<?php if (isset($current_domain)): ?>
    <?php if ($current_domain == 1): ?>
        <div class="show-this-on-primary-domain">
            <h1>Welcome to my primary website</h1>
        </div>
    <?php elseif ($current_domain == 2): ?>
        <div class="show-this-on-another-domain">
            <h1>Welcome to another website</h1>
        </div>
    <?php endif; ?>
<?php endif; ?>

(Source)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.