<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>

CC BY-SA 3.0
2017-02-16T18:48:15.570Z
This works, is there an advantage to using {% if sectionURL matches "/jobs/" %} vs. {% if sectionURL == "jobs" %}?
triplethreat23
CC BY-SA 3.0
2017-02-17T04:09:35.630Z
@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
Pindo
CC BY-SA 3.0
2017-02-16T07:49:54.227Z
2017-02-16T07:49:54.227Z
Pindo
<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>

CC BY-SA 3.0
2017-02-16T18:45:56.950Z
This code seems to return all sections.
triplethreat23
CC BY-SA 3.0
2017-02-16T11:12:08.647Z
2017-02-16T11:12:08.647Z
Justin Dekkers
<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>

CC BY-SA 3.0
2017-02-14T19:42:08.307Z
Just to be clear, that code is working for you and you're just wondering if there is a more efficient way?
Brad Bell
CC BY-SA 3.0
2017-02-15T03:13:34.627Z
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.
triplethreat23
<entries><sections><getsegment>
Get Entries From Any Section Matching a URL segment
# 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:

I want to load ENTRIES from any section where the first URL segment of the entry matches jobs.
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**: @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  

---

### 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.  

---

