0

Is there a way to check if a template page exists?

When we embed pages we do it like this

{embed="foo/bar"}

I was thinking if it was possible to do something like this

{if {template_exists path="some/path"}}
  PAGE EXISTS
{if:else}
  PAGE DOES NOT EXISTS
{/if}
2
  • 1
    Why would there be a conditional if a template existed or not? Could you give an example? – Johnathan Waters May 1 '14 at 13:59
  • Could you please give us more information or mark the question as answered? – Johnathan Waters May 7 '14 at 18:59
1

EDIT: I created a plugin to help if you want. http://devot-ee.com/add-ons/if-template-exists

You can do so with the query module (keep in mind your database prefixes may be different than "exp_"):

{query sql="SELECT 
                exp_templates.template_id
                FROM `exp_templates`
                LEFT JOIN `exp_template_groups`
                   ON exp_template_groups.group_id = exp_templates.group_id
                WHERE exp_template_groups.group_name = 'foo'
                   AND exp_templates.template_name = 'bar'
                limit=1"}

    [code if template exists]

    {if no_results} [code if template does not exist]{/if}
{/query}
0

You could use this plugin:

If Template Exists

http://devot-ee.com/add-ons/if-template-exists

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.