I have a relationship field which allows the editor to choose entries from different channels (channels about & news), and a few channels I have set up for Pages (with a Page URI). How can I make the template generate an appropriate URL for each entry? That is: how can I get it to link to /about/{url_title} for an about sub-page, /news/{url_title} for a news entry, and {pages_uri} for a page?

I think I can probably create a switchee scheme to create the link programmatically on the template depending on the case, but I wonder if there’s an EE tag for this.

2 Answers 2


I think you're on the right track with switchee, and something like the following should work:

    {exp:switchee variable="{your_relationship_field:channel}" parse="inward"}

        {case value="news"}
            <a href="{url_title_path='news/entry'}">{your_relationship_field:title}</a>
        {case value="about"}
            <a href="{url_title_path='about/entry'}">{your_relationship_field:title}</a>

        {case default="yes"}
            <a href="{your_relationship_field:page_url}">{your_relationship_field:title}</a>

  • I’ve accepted your answer, but want to document that I did something a bit different. Because pages (entries with a page_url) also belong to a channel, I used switchee to test your_relationship_field:page_url. If this variable has a value, then use that for the link, otherwise, use a nested switchee that checks your_relationship_field:channel_short_name and applies the correct path depending on that.
    – Alfonso
    Oct 23, 2013 at 21:25

One other option would be to use a switch only between channel entry versus page entry, as long as you have set up your channel entry comment template path setting in your channel settings. With that set in each channel, you can use the variable {comment_url_title_auto_path} for channel entries, and your page url for the page entries. That would simplify your conditional somewhat, though with switchee, that may not be necessary.

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.