sjelfull / craft3-templateselect

A fieldtype that allows you to select a template from the site templates folder.
https://superbig.co
MIT License
17 stars 9 forks source link

Use a separate template path. #4

Closed ipetrov87 closed 6 months ago

ipetrov87 commented 6 years ago

My idea is to make one matrix field with several components that can be used on many places. For that reason I want to have all my template, that are able to select, in one separated folder called components. In that folder I want to have sub-folders that contains all possible template for each component. Something like this:

project structure

So I add the template select field and set the sub-folder to component/textAndImage/. So when I go to my Homepage and select a template imageOnLeft.twig save it, and then I try to load the page I get this error:

Unable to find the template “imageOnLeft.twig” in "homepage/_entry" at line 5.

So instead to include component/textAndImage/imageOnLeft it just include imageOnLeft.twig.

Is it possible somehow to include the Limit to subfolder + Selected template instead just Selected template?

sjelfull commented 6 months ago

This is now available with v5.0.0.

These are the different options now:

Output the chosen template name:

{{ entry.fieldHandle }}

Include/Embed the chosen template:

{% include entry.fieldHandle %}

Include the template including subfolder if set:

{% include entry.fieldHandle.withSubfolder() %}

This is a alias for the following:

{{ entry.templateWithSubfolder.template(true) }}

Output the subfolder name:

{{ entry.fieldHandle.subfolder() }}

Output the filename without path:

{{ entry.fieldHandle.filename() }}