1

I created a Profile structure for my client's employees. He asked if I could generate an email signature for them from their Profile. I figured out a way to put all the signatures on one page using a

{% for entry in craft.entries.section('profiles') %}

loop on a single page.

However, is there a way to give each person their own page for an email signature? /PROFILE/email-signature that pulls content from the profile. I want this to update dynamically as he adds/removes employees.

How would I create a secondary template for the profiles for an email-signature?

  • Are you just asking how to create the details template for an entry in your structure like /profiles/john-doe ? Or are you asking how to have both /profiles/john-doe AND /profiles/john-doe/email-signature and they are both connected to one "John Doe" profiles entry? – Ryan Sep 14 '17 at 1:57
  • The second question... I need an email-signature page for every profile page, but still keep the profile pages. – Jeff Fulton Sep 14 '17 at 18:22
  • Ah, that's just a dynamic routes issue then. Solution is posted below. – Ryan Sep 14 '17 at 22:56
3

It sounds like you need to create a dynamic route by going to Settings > Routes > "New Route". Then you'd set your custom route to profiles/{slug}/email-signature and decide which template to serve when the url looks that way.

You can either serve the _entry template you're serving for /profiles/john-doe or create a new one. Depending on the situation, you may need to set the entry in the template like...

{% set person = craft.request.getSegment(2) %}
{% set entry = craft.entries.section('profiles').slug(person).first %}

...in the event Craft can't figure it out because you're on a separate template. Grabbing segment 2 means you're grabbing john-doe from the URL, which will help Craft know which entry to find.

Here's more info on routing in the docs: https://craftcms.com/docs/routing#dynamic-routes

2

This should be a comment on Ryan's answer, but I don't have the necessary reputation to post it.

If you're using a custom route like profiles/{slug}/email-signature then you don't need to use getSegment(2) to access the person. The whole point is that your setting the slug variable during the routing so should be able to just use {{ slug }} in the template that the route is pointed at.

So you'd just need: {% set entry = craft.entries.section('profiles').slug(slug).first %}

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.