rsanchez / resource_router

Resource Router for ExpressionEngine
MIT License
48 stars 12 forks source link

Hidden Templates #6

Closed siebird closed 10 years ago

siebird commented 10 years ago

Rob,

First time using resource router and I was banging my head for a couple minutes trying to figure out why the template was not being routed properly. So I duplicated the template without the hidden template indicator _ and updated the route and everything works as expected.

Not sure if this is as expected or a bug. Thanks for sharing man!

rsanchez commented 10 years ago

It should work with hidden templates. Can you post some more info on what you were trying to do? I can do some testing, then.

siebird commented 10 years ago

I have $config['hidden_template_indicator'] = '_'; and have routing templates in my default template group all prefixed with a underscore (_). So this was my first route that I was having issues with:

$config['resource_router'] = array(
    'item/:url_title' => function($router) {
        $router->setTemplate('site/_product_entry');
    }
);
rsanchez commented 10 years ago

I just confirmed: hidden templates do NOT work. I was mistaken about saying they should work.

Note to self: The problem is upstream in EE core. You cannot set a hidden template in the core_template_route hook. You'd probably have to manipulate the hidden template indicator on the fly to get it to accept a hidden template.

rsanchez commented 10 years ago

And just a note on your code above, if you aren't planning to do anything else in that callback function (ie. you are just setting a template), you can simply do:

$config['resource_router'] = array(
    'item/:url_title' => 'site/_product_entry',
);

Which is functionally equivalent to the example you have above.

siebird commented 10 years ago

Not a deal breaker. I removed all underscores from my routing templates. In the docs, the first example under the Why section is using hidden templates . which made me think they could be use, might want to update ;)

siebird commented 10 years ago

Good to know–that was from me tinkering at first why the route was not working. Thanks Rob

siebird commented 10 years ago

I tried the simple method and it's not working as expected. Is this because :url_title is considered a wildcard that checks the database? Switching page to the callback function routes the template properly

$config['resource_router'] = array(
    'item/:url_title' => 'site/product_entry',
);
rsanchez commented 10 years ago

Are you using a valid url title? If not it won't work. If you use a callback, the automatic validation won't occur, so that's why it works when this doesn't.

siebird commented 10 years ago

Yep, all single entry url's are created with the following: <a href="/item/{url_title}">

Does having thousands of entries affect this? Does the product_entry template channel:entries tag have anything to do with it?

{exp:channel:entries
    channel="products"
    disable="categories|category_fields|member_data|pagination|trackbacks"
    dynamic="yes"
}
rsanchez commented 10 years ago

It might. Are you doing {if no_results}{redirect="404"}{/if} in your channel:entries loop? I'm not sure dynamic="yes" will work. Try doing

dynamic="no"
url_title="{route_1}"
require_entry="yes"
siebird commented 10 years ago

Doh! I had a random , leftover from the callback that I just noticed. I tried your method with the parameters above and also switched back to what I had–both worked.

croxton commented 9 years ago

Just wanted to add to this: if you explicitly define the hidden template indicator in config.php, you CAN in fact route to hidden templates:

$config['hidden_template_indicator'] = '_';
robsonsobral commented 9 years ago

In case anybody is wondering why to route to a hidden template: