October showcase : display only elements of a certain category

October showcase : display only elements of a certain category

Posted By: pmietlicki

Published to Laravel on Jun 23, 2017

My main language is French and sometimes inside October you have plugins that are not genuinely "translatable" (like the showcase plugin).

If you are not willing to rewrite the plugin or extend it, you could use a "trick" to display only elements of a certain language :

  • Create new categories for each language you want to display (EN, FR, etc) inside the showcase plugin
  • Add the component "Item lists" of the showcase plugin
  • Add the component "Locale Picker" inside your layout or specific Web Page
  • On the code part, use this function
function onEnd()
{
foreach ($this->items as $key => $item) { if (isSet($item->categories[0]->name) && !empty($item->categories[0]->name)) { if ($item->categories[0]->name!=strtoupper(\RainLab\Translate\Classes\Translator::instance()->getLocale())) unset($this->items[$key]); } }
}

It is a very ugly solution (and you should add some verification) but it works !

Tags: laravel, October, php

Archive