Jump to content

How can I find templates from a folder which isn't the Templates folder?


Rodd
 Share

Recommended Posts

Hi everyone,

I'm not sure it's possible, but I'm asking. Maybe someone has a solution. Is it possible, when you want to create a template in the Processwire dashboard, to specify a template file from another folder which is different of the Template folder?

In fact, I don't want to change the actual source which is the folder. I just want to find a way to recognize my templates which can be in a folder which is in the template folder, and use the find() function like this :

<?php 

$childChildren = $pages->find("template=templatesWhichAreInTheSpecificFolder, sort=sort");
?>

I don't know if you understand my demand, but if you want more details, don't hesitate to ask.

Thanks by advance!

Link to comment
Share on other sites

There is no easy way I know of to do exactly what you're asking for. But as far as I understand the actual need is to find pages with selected templates.

If you do not need to select the templates to be used in selector in admin, you should be able to hard-code the selector like this (see here for explanation):

<?php 

$childChildren = $pages->find("template=template-a|template-b|template-c, sort=sort");

If you need to be able to select the templates in admin, you could add this module to some page, and then use it's value in a selector. Hope the module still works in current version of PW.

There is an option to tag fields in admin and then use the tag instead of a list of fields in selectors. If the same thing worked for templates, that could be a good way to solve this task. But I did not find any docs on that, so you just might want give it a try first, and then fallback to the module if it's not possible.

 

  • Like 3
Link to comment
Share on other sites

The idea from @Ivan Gretsky of using template tags (which are on the Advanced tab of Edit Template) seems like a really good one.

An approach to searching for tags on templates is here:

Another possibility would be to prefix each relevant template name (e.g. "prefix-templatename") and then find using the "starts with" operator:

$foundPages = $pages->find("template^=prefix");

But I think the tags approach would probably be better – more flexible, and organises things nicely on the Templates page in the admin.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...