Answers.Body: <p>To check if the word <code>jobs</code> is in the <code>sectionUrl</code> you can use twig's <code>matches</code> to create a regular expression that looks for <code>jobs</code></p>
  
  <pre><code>{% set allSections = craft.sections.getAllSections() %}
  {% for section in allSections %}
      {% set sectionURL = section.getUrlFormat()|split('/')[0] %}
  
      {% if sectionURL matches "/jobs/" %}
          {{ section.name }}
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T18:48:15.570Z
Answers.Text: This works, is there an advantage to using {% if sectionURL matches "/jobs/" %} vs. {% if sectionURL == "jobs" %}?
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-17T04:09:35.630Z
Answers.Text: @triplethreat23 `matches` will match any string that contains `jobs` e.g `/a-jobs-list/` and using `==` matches a string that is only `jobs`. If you're looking to find a string that contains the string `jobs` then matches would be what you're after but if you're looking for a specific string then `==` would be appropriate
Answers.UserDisplayName: Pindo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T07:49:54.227Z
Answers.LastActivityDate: 2017-02-16T07:49:54.227Z
Answers.UserDisplayName: Pindo
Answers.Body: <p>If I understand you right all you need is:</p>
  
  <pre><code>{% for section in allSections if craft.request.getFirstSegment() == 'jobs' %}
  
   {# other code here #}
  
  {% endfor %}
  </code></pre>
  
  <p>You can give conditions to your for loop which saves you another if statement. You also dont need to split any url because craft already got Segment selection which is found here:
  <a href="https://craftcms.com/docs/templating/craft.request/" rel="nofollow noreferrer">https://craftcms.com/docs/templating/craft.request/</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T18:45:56.950Z
Answers.Text: This code seems to return all sections.
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T11:12:08.647Z
Answers.LastActivityDate: 2017-02-16T11:12:08.647Z
Answers.UserDisplayName: Justin Dekkers
Body: <p>I have 2 issues that I need help with:</p>
  
  <ol>
  <li><p>I want to load ENTRIES from any section where the first URL segment of the entry matches jobs.</p></li>
  <li><p>I am using the code below to load any SECTION where the first URL segment matches jobs.  This code works to load the sections. I'm just wondering if there's a more efficient way to write this to load the sections.  This is separate from loading the entries.  I need to do both.</p>
  
  <pre><code>{% set allSections = craft.sections.getAllSections() %}
  
  {% for section in allSections %}
  
  {% set sectionURL = section.getUrlFormat()|split('/')[0] %}
  
  {% if sectionURL == "jobs" %}
      {{ section.name }}
  {% endif %}
  
  {% endfor %}
  </code></pre></li>
  </ol>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-14T19:42:08.307Z
Comments.Text: Just to be clear, that code is working for you and you're just wondering if there is a more efficient way?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-15T03:13:34.627Z
Comments.Text: I want to know how to get entries where the 1St url segment matches jobs. That code is working to get the sections with the 1st URL segment jobs. I am also wondering if there is a more efficient way to get the sections.
Comments.UserDisplayName: triplethreat23
Tags: <entries><sections><getsegment>
Title: Get Entries From Any Section Matching a URL segment
ThreadText: # Get Entries From Any Section Matching a URL segment
  
  (Asked by: username_0 on 2017-02-13)
  
  I have 2 issues that I need help with:
  
  1. I want to load ENTRIES from any section where the first URL segment of the entry matches jobs.
  2. I am using the code below to load any SECTION where the first URL segment matches jobs. This code works to load the sections. I'm just wondering if there's a more efficient way to write this to load the sections. This is separate from loading the entries. I need to do both.
  
     ```
     {% set allSections = craft.sections.getAllSections() %}
  
     {% for section in allSections %}
  
     {% set sectionURL = section.getUrlFormat()|split('/')[0] %}
  
     {% if sectionURL == "jobs" %}
         {{ section.name }}
     {% endif %}
  
     {% endfor %}
  
     ```
  
  **Tags:** entries, sections, getsegment
  
  > **Comments:**
  > **username_1**: Just to be clear, that code is working for you and you're just wondering if there is a more efficient way?  
  > **username_0**: I want to know how to get entries where the 1St url segment matches jobs. That code is working to get the sections with the 1st URL segment jobs. I am also wondering if there is a more efficient way to get the sections.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-02-16. Score: 2
  
  To check if the word `jobs` is in the `sectionUrl` you can use twig's `matches` to create a regular expression that looks for `jobs`
  
  ```
  {% set allSections = craft.sections.getAllSections() %}
  {% for section in allSections %}
      {% set sectionURL = section.getUrlFormat()|split('/')[0] %}
  
      {% if sectionURL matches "/jobs/" %}
          {{ section.name }}
      {% endif %}
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: This works, is there an advantage to using {% if sectionURL matches "/jobs/" %} vs. {% if sectionURL == "jobs" %}?  
  > **username_2**: @username_0 `matches` will match any string that contains `jobs` e.g `/a-jobs-list/` and using `==` matches a string that is only `jobs`. If you're looking to find a string that contains the string `jobs` then matches would be what you're after but if you're looking for a specific string then `==` would be appropriate  
  
  ---
  
  ### Answer by username_3 on 2017-02-16. Score: 1
  
  If I understand you right all you need is:
  
  ```
  {% for section in allSections if craft.request.getFirstSegment() == 'jobs' %}
  
   {# other code here #}
  
  {% endfor %}
  
  ```
  
  You can give conditions to your for loop which saves you another if statement. You also dont need to split any url because craft already got Segment selection which is found here:
  <https://craftcms.com/docs/templating/craft.request/>
  
  > **Comments:**
  > **username_0**: This code seems to return all sections.  
  
  ---
  
  