I'm assuming you have a field on your nodes with the name field_domain
.
On your website:
- Create a new node. This will be a place holder.
- Get the NID.
a) Go go /admin/content/
b) Click edit on this placeholder node
c) Check the url. It will be in the form:
/node/<NID>/edit
Get that NID
.
- Go to your theme.
- On the templates folder, create a file with the name:
node--NID.tpl.php
so something like: node--78.tpl.php
- On this file, put the following content:
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1) // published
->fieldCondition('field_domain', 'value', $_SERVER['SERVER_NAME'], '=');
$result = $query->execute();
$nid = array_keys($result['node'])[0];
if($nid) {
$nodeObj = node_load($nid);
$nodeRndr = node_view($nodeObj);
print(drupal_render($nodeRndr));
}
You need to update 2 things:
article
to the machine name of the content type you're using.
field_domain
to the machine name of the field you're using.
- Now, go to
admin/config/system/site-information
- Change the front page to
node/NID
where NID is the value from #4.
Explanation:
What that code does is checks $_SERVER['SERVER_NAME']
. This should be the domain that's being used. Using that, it looks to see if there's a node
with the field field_domain
that has a value that matches $_SERVER['SERVER_NAME']
.
If there's a match, it will load the node and render it.
If not, it should still load the placeholder node you created. This could be your default home page.
Hope this helps.
Original comment:
Have you considered writing some custom code?
If the only thing different is the title. I would create a small module that:
- On installation creates a table with a domain and a title column.
- When a page loads, reads the table and matches the domain and selects the title.
- With the title, on...
hook_preprocess_page
(probably) you can set the title
I think there's a bit more functionality you want. If you're acting like a broker or if it's only a single owner, you probably are sending an email. So you would need the domain that was visited in the form as a minimum.
You can do this by having a hidden field and setting the value on load as well.
Or when submitting the form, reading it and processing it.
If it's more like a marketplace and you're sending an email to the owner which would vary per domain.
I think that processing that after the fact and only having one form would probably be more efficient than having a form per domain.
It depends on the use case. Just offering another option.