diff --git a/CHANGELOG.md b/CHANGELOG.md index 958b56d..646bbba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.3 + +- Custom widget template + ## 1.0.2 - Folders protection diff --git a/README.md b/README.md index 389543a..f19ff7b 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,40 @@ Filter by place id with the `place_ids` widget param (comma separated): **Note:** Only places imported in the current context language will be displayed +## Custom template + +You can create your own template to display places. + +Create a new template file in the **pixel_googlemybusiness** directory for your theme: + +*themes/{themeName}/modules/pixel_googlemybusiness/custom.tpl* + +```html +{foreach from=$places item=place} + {$place->getPlaceId()} + {$place->getName()} + {$place->getRating()} + {$place->getUserRatingsTotal()} + {foreach from=$place->getOpeningHoursWeekdayText()|json_decode:1 item=hour} + {$hour} + {/foreach} + {foreach from=$place->getReviews() item=review} + {$review->getAuthorName()} + {$review->getTime()|date_format:"%e %B %Y"} + {$review->getRating()} + {if $review->getComment()} + {$review->getComment()} + {/if} + {/foreach} +{/foreach} +``` + +Add the **template** option in the widget with the template path: + +```smarty +{widget name='pixel_googlemybusiness' template='module:pixel_googlemybusiness/custom.tpl'} +``` + ## Translations In admin, go to the **Translations** page under the **International** menu. \ No newline at end of file diff --git a/pixel_googlemybusiness.php b/pixel_googlemybusiness.php index 1468e09..ca19c64 100644 --- a/pixel_googlemybusiness.php +++ b/pixel_googlemybusiness.php @@ -22,7 +22,7 @@ class Pixel_googlemybusiness extends Module implements WidgetInterface public function __construct() { $this->name = 'pixel_googlemybusiness'; - $this->version = '1.0.2'; + $this->version = '1.0.3'; $this->author = 'Pixel Open'; $this->tab = 'front_office_features'; $this->need_instance = 0; @@ -73,17 +73,20 @@ public function uninstall(): bool * @param array $configuration * * @return string + * @throws ContainerNotFoundException */ public function renderWidget($hookName, array $configuration): string { $keys = [$this->name, md5(serialize($configuration))]; $cacheId = join('_', $keys); - if (!$this->isCached($this->templateFile, $cacheId)) { + $template = $configuration['template'] ?? $this->templateFile; + + if (!$this->isCached($template, $cacheId)) { $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); } - return $this->fetch($this->templateFile, $cacheId); + return $this->fetch($template, $cacheId); } /**