0

Is there a way to check if a template group exists either in the templates or in a add-on?

For example, I would want to do something like this

{if {exp:foo:template_exists name="blog/test"} == "true"}
    {embed="bar/qux"}
{if:else}
    {redirect="404"}
{/if}
2
  • 1
    If you have a blog/test template it will always exist so will always return true. Perhaps you can explain what you're trying to do as there's most likely another way of achieving it. – Bluedreamer Dec 20 '13 at 6:12
  • {exp:foo:template_exists} isn't really implemented. The reason why I was asking this question is to that I can implement it. – developarvin Dec 20 '13 at 7:21
1

As far as i'm aware this functionality is built in by default, if there is no template then it'll automatically 404 error.

Please see the ExpressionEngine URL Schematic here: http://www.jamessmith.co.uk/images/ExpressionEngine_url_schematic.png

1
  • What I wanted is some sort of function where I can pass a url, because I am going to use it in an add-on. – developarvin Dec 23 '13 at 0:51
0

As other have said, this is built in by default. Have a look at this article by Jovia Web Studio if you want to implement a more stringent 404 policy on your site. Comment are interesting as well.

2
  • 2
    I think he's trying to see if a template group other than the currently visited one exists. Basically, "Does that other page exist? If so, do this here on this page. If not, redirect this page as if it doesn't exist either." – Stephen Callender Dec 20 '13 at 13:10
  • @StephenCallender Yep, that is what I want. – developarvin Dec 23 '13 at 0:50
0

What you are trying to do should be done using an Ajax function. Something like this:

$.ajax({
    type: 'HEAD',
    url: 'http://www.example.com/template_group/',
    success: function() {
        alert('Page found.');
    },  
    error: function() {
        alert('Page not found.');
    }
});

If there's an error, redirect to your 404 page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.