# Snippet to create sub-directories in URI but not sub-resource

**URL:** <https://community.modx.com/t/snippet-to-create-sub-directories-in-uri-but-not-sub-resource/2285>\
**Category:** Development\
**Created:** [February 21, 2020, 2:03pm UTC](https://community.modx.com/t/snippet-to-create-sub-directories-in-uri-but-not-sub-resource/2285 "2020-02-21T14:03:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffsydor](https://community.modx.com/user_avatar/community.modx.com/jeffsydor/32/363_2.png) [@jeffsydor](https://community.modx.com/u/jeffsydor)\
**Post date:** [February 21, 2020, 2:03pm UTC](https://community.modx.com/t/snippet-to-create-sub-directories-in-uri-but-not-sub-resource/2285/1 "2020-02-21T14:03:55Z")

</div>

So I inherited a website that uses a bunch of PHP with zero comments explaining things. I am stuck on a function that is supposed to create links that modify the URI to look like a sub-directory rather than creating a physical resource underneath.

Here’s the function:

> ```
> function getTabParams($link, $name){
> global $modx;
> $params = array();
> $typeValue = !empty($_GET['type']) ? strip_tags($_GET['type']) : '';
>     
> if(checkTabAvailability($link)){
> $params = array(
> 'class' => ($typeValue == $link) ? 'active' : '',
> 'name' => $name,
> 'link' => !empty($link) ? $modx->resource->get('uri').($modx->resource->get('isfolder') == 1 ? '' : '/').$link : $modx->resource->get('uri')
> );
> }    
> return $params;
> }
> 
> ```

The line in question is this:

> ```
> 'link' => !empty($link) ? $modx->resource->get('uri').($modx->resource->get('isfolder') == 1 ? '' : '/').$link : $modx->resource->get('uri')
> 
> ```

Also, checkTabAvailability is a big block of code but here’s just one case for reference:

> ```
> function checkTabAvailability($type){
> global $modx;
> switch($type){
> case 'people':
> $c = $modx->newQuery('modResource');
> $c->leftJoin('modTemplateVarResource','TV1','TV1.contentid=modResource.id'); 
> $c->where(array('template:IN' => [16,39,40], 'published' => 1, 'TV1.tmplvarid' => 81, 'TV1.value:LIKE' => '%'.$modx->resource->get('link_attributes').'%'));
> $c->select(array('modResource.id as id'));
> if(!$modx->getCount('modResource', $c)){
> return false;
> }
> return true;
> break;
> default: // all
> return true;
> }
> }
> 
> ```

For some reason only a handful of templates will successfully link to these “pages”. But if I’m building my own template or if I duplicate the template, it will not link properly. Just ends with a 404 page.

Anybody have any thoughts? Thanks

---

<div class="post-metadata">

**Author:** ![paulp](https://community.modx.com/user_avatar/community.modx.com/paulp/32/58_2.png) [@paulp](https://community.modx.com/u/paulp)\
**Post date:** [February 21, 2020, 2:19pm UTC](https://community.modx.com/t/snippet-to-create-sub-directories-in-uri-but-not-sub-resource/2285/2 "2020-02-21T14:19:57Z")

</div>

Might be well off but could it be this line that seems to list template id’s ?

```auto

$c->where(array('template:IN' => [16,39,40], 'published' => 1, 'TV1.tmplvarid' => 81, 'TV1.value:LIKE' => '%'.$modx->resource->get('link_attributes').'%'));

```

---

<div class="post-metadata">

**Author:** ![jeffsydor](https://community.modx.com/user_avatar/community.modx.com/jeffsydor/32/363_2.png) [@jeffsydor](https://community.modx.com/u/jeffsydor)\
**Post date:** [February 21, 2020, 2:47pm UTC](https://community.modx.com/t/snippet-to-create-sub-directories-in-uri-but-not-sub-resource/2285/3 "2020-02-21T14:47:49Z")

</div>

Unfortunately, these aren’t the templates that work with it. They are just the ids for the bio types for employees. This line just gathers all resources using those template ids, that have a string within TV 81 that matches the **link\_attributes** field for the resource I’m currently viewing.

Here’s a different case for comparison:

> ```
> case 'experience':
> $_tv = $modx->newQuery('modTemplateVarResource');
> $_tv->where(array('modTemplateVarResource.contentid' => $modx->resource->get('id'),'modTemplateVarResource.tmplvarid' => 118)); // ServiceExperience
> $_tv->select(array('modTemplateVarResource.value as value'));
> $_tv->prepare();
> ///echo $_tv->toSQL();
> $_tv->stmt->execute();
> $_tv_res = $_tv->stmt->fetch(PDO::FETCH_ASSOC);
> if(empty($_tv_res) || empty($_tv_res['value'])){
> return false;
> }
> return true;
> break;
> 
> ```

---

<div class="post-metadata">

**Author:** ![bobray](https://community.modx.com/user_avatar/community.modx.com/bobray/32/46_2.png) [@bobray](https://community.modx.com/u/bobray)\
**Post date:** [February 21, 2020, 5:53pm UTC](https://community.modx.com/t/snippet-to-create-sub-directories-in-uri-but-not-sub-resource/2285/4 "2020-02-21T17:53:59Z")

</div>

What is the $type value when the trouble occurs?
