1

I need to be able to generate private links for entries that aren't visible on the front-end of the website. I guess I could just setup an alternative template that isn't linked within the website structure. The links don't need to be very secure but this still feels a bit half-baked. Has anyone setup something like this before?

3
  • If they aren't visible on the front-end of the website then there's not much point linking to them(?). The standard approach for this would be to limit access to a particular Member Group and then when the user is logged in on the front-end and authenticated as part of that member group then they'd be able to see the content whereas all other users wouldn't. Is that what you're trying to achieve?
    – Ian Young
    Commented Apr 15, 2014 at 8:20
  • An example use-case is sending an external contributor a link to the entry for approval before it's published or giving special customers advanced previews before an item is publicly available. I want to avoid user having to login.
    – Dylan
    Commented Apr 15, 2014 at 8:44
  • Better Workflow has a feature called "external previews" designed specifically for the purpose you just described, Dylan. betterworkflow.electricputty.co.uk
    – Alex Kendrick
    Commented Apr 15, 2014 at 13:44

1 Answer 1

5

If it doesn't need to be particularly secure, create a separate sub-domain, and set up a global variable to show different statuses depending on which sub-domain they're on. If you're using FocusLab Master Config this is simple, otherwise try something like this in your main public index.php file under where it says "CUSTOM CONFIG VALUES":

switch($_SERVER["HTTP_HOST"]) { 
  case "previews.domain.com" : 
    $assign_to_config['site_url'] = 'http://previews.domain.com/'; 
    $assign_to_config['global_vars']['gv_entry_statuses'] = 'open|Draft';
    break;  
  case "www.domain.com" :
  case "domain.com" :
    $assign_to_config['site_url'] = 'http://www.domain.com/';
    $assign_to_config['global_vars']['gv_entry_statuses'] = 'open';
    break;
}

Then any time you use a channel entries tag, add the parameter status="{gv_entry_statuses}"

You can use this technique to allow editors a quick and simple workflow for creating new content before launching to the live site. Rather than using the 'closed' status you should really create a new custom status for this, such as "draft" or "pending", because it's useful to keep "closed" for stuff that really should never appear anywhere ever (but for some reason needs to be kept in the system).

You can also use this technique for quick and dirty forking into separate templates, e.g. you could specify a different folder for tmpl_file_basepath using $assign_to_config['tmpl_file_basepath'] so that the sub-domain displays a completely different version of the site. (Much better to use a proper version-controlled environment with Git deployments, but that can take a while to set up and is not necessary for really small sites.)

2
  • Very clever technique! I like it. Commented Apr 15, 2014 at 13:03
  • Thanks, this looks like a nice approach and I'm already setup with the FocusLab Master config and git so it should be pretty simple to implement.
    – Dylan
    Commented Apr 17, 2014 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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