calebgrove / content-viewer

A nifty little Kirby widget that allows you to show a block of Kirbytext or Markdown content in Kirby's panel.
MIT License
15 stars 6 forks source link

Plugin conflicts with multilanguage site #2

Closed mciszczon closed 6 years ago

mciszczon commented 7 years ago

While developing a site I installed many plugins and additional fields and so on. At some point I noticed my multilang site was not working properly.

Changing language was not working. I could change the language, the page was redirected (example.com/en), all the language variables were changed (for example $site->language() is changed correctly) and it was fine, but snippets fetching pages' content still fetched the default language content.

I finally found out it was caused by your plugin, this part:

// If the page doesn't exist yet, create it.
if(!site()->index()->findBy('intendedTemplate', 'content-viewer')) {
    site()->create('content-viewer', 'content-viewer', array(
        'title' => '',
        'text' => ''
    ));
}

Not really sure how this affects multilang config, but it surely does. Just commenting this part and it works again.

mciszczon commented 7 years ago

As I understand this, that part of code shouldn't even run as I have got pages for the content-viewer plugin created.

Are you sure that you can negate site()->index()->findBy('intendedTemplate', 'content-viewer')? Because I changed the if to:

if(!site()->findBy('intendedTemplate', 'content-viewer')) {

And multilang works fine.

calebgrove commented 7 years ago

Uh-oh, that's strange. The reason why I have site()->index() is because findBy() only searches the root level otherwise. Unfortunately, I don't have time to look into this right now, but I'll put it near the top of my priority list.

calebgrove commented 7 years ago

So, I just released a hotfix for this problem by using your code. However, this change does mean that the content-viewer page must be in the root level of the content folder. This is probably not a big problem, as that is where the plugin stores it by default, but it would be nice to allow people to move it into another directory of they so desire without breaking the plugin.

Hence, I'll leave this issue open for now.

mciszczon commented 7 years ago

I may play a little bit with the original code to see what was happening. Maybe I'll find the reason for this. Will let you know if I do.

calebgrove commented 6 years ago

Gonna go ahead and close this issue, as no-one has said that having the content file for the plugin anywhere besides the root content folder is something important to them.