ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Use segment to get channel data

July 04, 2014 2:29pm

Subscribe [2]
  • #1 / Jul 04, 2014 2:29pm

    eigotec

    19 posts

    Hi,

    First post, so please go easy on me 😊

    So, I am working on a site where users enter data in to a channel…Lets say exam results.

    What i want to do is have a list of students and when you click on their name it will go to
    http://example.com/student-name/results and show the results of the student (i.e student-name).

    Is this possible with the core or does it have to be done through template routes in the premium version.

    Any input is appreciated.

    Thanks.

  • #2 / Jul 07, 2014 2:43pm

    Boyink!

    5011 posts

    Is your example URL a hard requirement?

  • #3 / Jul 07, 2014 3:23pm

    eigotec

    19 posts

    No I’m open to any URL structure really. Thanks

  • #4 / Jul 07, 2014 3:38pm

    Boyink!

    5011 posts

    OK - then this is really simple. EE inherently wants to get information from the URL to know what results to return. The main tag you use in a template to return results is channel:entries. It has a property called “dynamic” that is by default set to “yes”. This means it will look to the URL for direction, setting dynamic to no means the channel:entries tag will ignore the URL.

    You could create a template group called “results”, and in the results/index template have roughly the following code:

    {exp:channel:entries channel="exam_results" limit="1"}
      {title}
      {other-channel-fields}
    {/exp:channel:entries}

    If your entries in the Exam Results channel were titled by student name then a URL of

    http://yoursite.com/results/mike-boyink

    Would load the index template of the Results template group and retrieve the contents of the entry posted with my name as the title.  EE knows what entry to pull because the channel:entry tag has been left in dynamic mode, so the channel:entries tag will look to the URL, find the url-title of “mike-boyink”, and retrieve that entry from the specified (exam_results) channel.

  • #5 / Jul 07, 2014 3:59pm

    eigotec

    19 posts

    Thanks a lot for your help Boyink! Much simpler than I thought it would be. Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases