Hello,
I’ve started using the patterns plugin, and initial impressions are THIS IS GREAT!!
However, I’m running into issues for those patterns that require a specific ($page
) context. For example, I have the following pagination component:
<nav class="c-pagination">
<p class="c-pagination__count">
<strong><?= $pagination->items() ?></strong> results.
<? if($pagination->hasNextPage()): ?>
Showing <strong><?= $pagination->numStart() ?></strong> - <strong><?= $pagination->numEnd() ?></strong>
<? endif ?>
</p>
<p class="c-pagination__pages">
<? if($pagination->hasPrevPage()): ?>
<a rel="prev" href="<?= $pagination->prevPageURL() ?>">Previous</a>
<? endif ?>
<? if($pagination->hasNextPage()): ?>
<a rel="next" href="<?= $pagination->nextPageURL() ?>">Next</a>
<? endif ?>
</p>
</nav>
Of course, outside the context of search results, this template makes little sense. I need to have this pattern render in a context where a value for $pagination
is given. Ah, this is what the preview
configuration value is for I thought, so I provided the following:
<?php
return [
'preview' => function() {
site()->visit('search?q=brighton');
}
];
However, this has no effect. My impression was that this value simulates visiting a particular page, and then provides a pattern with the values needed. Is this not the case?
Additionally, for other patterns, I get a different error. So, for this configuration:
<?php
return [
'preview' => function() {
site()->visit('companies/south-eastern');
return [
'stations' => $pages->children()->filterBy('company', '*=', 'companies/south-eastern'),
'context' => 'company'
]
}
];
I get the following error:
Parse error: syntax error, unexpected '}', expecting ';' in /Users/paulrobertlloyd/Sites/bradshawsguide/site/patterns/section/stations/stations.config.php on line 11
Fatal error: Exception thrown without a stack frame in Unknown on line 0
Fatal error: Uncaught Whoops\Exception\ErrorException: Exception thrown without a stack frame in Unknown:0 Stack trace: #0 /Users/paulrobertlloyd/Sites/bradshawsguide/site/plugins/patterns/vendor/filp/whoops/src/Whoops/Run.php(356): Whoops\Run->handleError(16, 'Exception throw...', 'Unknown', 0) #1 [internal function]: Whoops\Run->handleShutdown() #2 {main} thrown in Unknown on line 0
What am I doing wrong? Am I configuring my patterns properly?