Skip to content

Commit

Permalink
Custom widget template
Browse files Browse the repository at this point in the history
  • Loading branch information
magentix committed Feb 17, 2023
1 parent b79c7fc commit 334df66
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.3

- Custom widget template

## 1.0.2

- Folders protection
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 6 additions & 3 deletions pixel_googlemybusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 334df66

Please sign in to comment.