3

Most of the pages in my Craft site are contained in one big Structure. There are a couple of pages whose content needs to exist in two locations within the structure. I'm not sure how best to do this.

I could probably hack something together with a bespoke route that loads a template which sets variables related to the navigation, then loads the content from the Entry defined in the CMS... but that seems like a horrible hack, and at that point I'd start to think I should just manually copy and paste the content between the two Entries in the CMS.

Any other ideas? Ideally I'd like it to be manageable in the CMS so it's not too hidden away from the client.

4

You could add a new entry type "Duplicate" to your section with just an entries field "Use content from entry".

In your template you can now overwrite your entry variable with:

{% set entry = entry.type == 'dupe' ? craft.entries.id(entry.contentFrom.first().id).first() : entry %}

You could also use the "Duplicate" entry type to link to the same entry / URL twice from your navigation:

{% nav entry in entries %}
    {% if entry.type == 'dupe' %}
        {% set entry = craft.entries.id(entry.contentFrom.first().id).first() %}
    {% endif %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endnav %}

And in case someone "guesses" the URL, simply redirect them to the original entry:

{% if entry.type == 'dupe' %}
    {% set entry = craft.entries.id(entry.contentFrom.first().id).first() %}
    {% redirect entry.url %}
{% endif %}
  • While Aaron's solutions would both work, this is a lovely idea Carl, and it works really well. It was simple to get working and is very transparent for, and editable by, the person using the CMS. Thanks. – Phil Gyford Jun 18 '15 at 10:49
  • No problem, Phil. Be careful with creating very similar pages and use the canonical meta tag to avoid them be rated as duplicate content by search engines! You do want / need different URLs, right? Otherwise you could just link to the same URL twice from your menu (also user editable with an entry type and help of smart Twig code). – carlcs Jun 18 '15 at 11:04
4

There are two easy ways to avoid copying and pasting or having duplicate entries.

First, you can use Globals to store the shared information.

Alternatively, your second entry/template can just ask for the data from the entry of the first entry.

{% set shared_information = craft.entries.slug('my-first-entry-slug').first() %}

<p>{{shared_information.customFieldWithSharedInformation}}</p>
  • That seems less nasty than my hacky suggestion, thanks :) I guess there's no way to make this more transparent within the CMS though... – Phil Gyford Jun 15 '15 at 14:25
  • You can make use of your field's instructions to let the user know "this content will appear on page x and page y" to make the management a bit easier! – Aaron Berkowitz Jun 15 '15 at 14:30
  • Although that assumes a field which is only on that one page, rather than shared across every page in the Structure. Maybe I'm asking too much :) – Phil Gyford Jun 15 '15 at 15:31
2

Theres a button in the edit entry page that allows you to save the current entry as a new one, just click the arrow next to the save button and you should see the option in the dropdown.

dupe entry button

This will essentially duplicate the entry :)

  • But presumably that is much the same as creating a new Entry and copying and pasting the content into it? I want the Entry to exist in two places - edit it once and the changes appear on two pages on the site. – Phil Gyford Jun 15 '15 at 14:24
  • Gotcha, sorry thought you meant a straight duplication, not multiple relations – Alec Ritson Jun 15 '15 at 14:26

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.