I’m trying to use content representations in my routing. In general routing like this works fine, but with content representations not anymore. The following router settings are great without ‘.txt’ but with ‘.txt’ I get an error: “Kirby::render() must be an instance of Page”. Is there a solution how to use content representations in router settings?
array(
'pattern' => '(en|de|es)/folder/(f1.txt|f2.txt|f3.txt)/(:all)',
'action' => function($lang, $func, $variable) {
$data = array(
'variable' => $variable
);
site()->visit('folder/'.$func, $lang);
return array('folder/'.$func, $data);
}
)
Just templates: f1.txt.php, f2.txt.php and f3.txt.php
Ok, but your page is still the folder name (whatever it is) and you are trying to call it as a page. You’d have to load the template instead, using tpl::load or something like that.
You mean loading the template manually like it is explained here: Organizing templates in subfolders? might be a solution?
Exactly. With $site->visit() you can only visit a page, not a template.
Too sad… I hoped the logic of content representations is implemented in site()->visit()…
@texnixe is there any chance to get a nativ (means KIRBY) info about content representations in the controller without checking the URL.
Why don’t you want to go with the tpl::load()
solution?
Oh, because this Post was the only info I got about tpl::load() apart from this: https://getkirby.com/docs/toolkit/api/tpl/load and I use routing on a multi language site. So if you have more examples to this method I would be happy. Besides I solved the issue with minifying in runtime depending on the template. This was the reason 'cause I asked for CRep inside the controller.
Yes, the documentation is a bit quiet on this, but there are some examples hidden here in the forum that you should be able to find using search.
Well, I don’t quite see your use case and how minifying relates to the issue, I think that information is missing here…
But fine if your issue is solved.
Yeah… I will post it as a small work-around - maybe somebody needs it… (MINIFY)