Yeah, you are right, this seems really weird. I just tested this and found that with one template I used, the correct template was shown, but with all other templates it failed, showing âdefaultâ instead.
While $dashboard->intendedTemplate() shows the uid, which is not correct either.
I donât think so, I tested this with about 12 - 18 blueprints/templates, none of which had any special characters in their filenames. But maybe we should test with a fresh starterkit first.
i think i encountered something similar before. i did forget to create the template file and only had the blueprint. then the create function did not work either. could it be that i have a missing (check, seems not) or broken template/blueprint? my buleprints are (almost) valid yaml just check again. some contain a regex passage like this which is NOT (edited) accepted by yaml validators.
telefon:
width: 1/3
label: Telefon
type: tel
required: true
help: Bitte geben Sie Telefon und Faxnummern komplett mit Vorwahl, jedoch ohne Sonderzeichen wie z.B. Klammern oder Punkte ein.
validate:
match: "/^\d[\d ]+\d$/"
I just tested this in a fresh starterkit with the available blueprint/template pairs and it worked perfectly, so the question is why it does not work in the other cases, in the other project where I tested this first, all blueprint/template pairs were available as well and nothing special in yaml.
it did work before with the vaidate. today i just added two new templates/blueprints (with no regex) and now its broken. i checked my repo not much else changed. does kirby cache this âregistryâ between session?
why does getting the template directly after creating it work with find() but not when using the page() function? page() is used for the return value of create(), right?
// HERE: create page omitted then...
$dashbox = kirby()->site()->page($newUriForDashbox);
echo '1:'.$dashbox->template(); // = default, which is wrong. should be 'dashbox'
$dashbox = $pages->find($newUriForDashbox);
echo '2:'.$dashbox->template(); // = dashbox, which is right
But you said above, that even then the $page->intendedTemplate() method does not output the intended template but the page uid? While it should output the name of the text file, not the foldername.
I think the problem must be something else, as it all works perfectly as it should with a fresh starterkit. Only I have no idea at the moment, what could be causing this issue. Maybe @lukasbestle to the rescue?
/**
* Returns the name of the content text file / intended template
* So even if there's no such template it will return the intended name.
*
* @return string
*/
public function intendedTemplate() {
if(isset($this->cache['intendedTemplate'])) return $this->cache['intendedTemplate'];
return $this->cache['intendedTemplate'] = $this->content()->exists() ? $this->content()->name() : 'default';
}