Perry
1
Hello,
How can I use the page name on the other side?
I tried this:
`
snippet
<?php snippet('slider',['slider_id' => 'slider-'.$counter,'source' => 'slider']) ?>
template
$filenames = $site->find($source)->slider_images()->split(',');
`
error
Call to a member function slider_images() on boolean
greetings perry
bnomei
2
forward the current page object (or any other) as ‘source’.
<?php snippet('slider',['slider_id' => 'slider-'.$counter,'source' => $page]) ?>
you can remove the site->find() part then.
$filenames = $source->slider_images()->split(’,’);
Perry
3
@bnomei thank you for your answer.
The website is a OnePager, I use the $page->title() for the sections.
If I know the page title it works:
<?php
$pagename = $site->find('slider');
snippet('slider',['slider_id' => 'slider-'.$counter,'source' => $pagename])
// Transform the comma-separated list of filenames into a file collection
$filenames = $source->slider_images()->split(',');
$filenames = array_pad($filenames, 2, '');
$files = call_user_func_array(array($source->files(), 'find'), $filenames);
?>
But how to do when I dont know the page title ?
<?php if($section->intendedTemplate() == "slider" ): ?>
<section id="<?php echo $section->title() ?>" class="article-wrapper"> <div class="content grid-24-24 flex align-content-space-between center">
<?php $counter++ ?>
<?php $test = $section->title() ?>
<?php $pagename = $site->find($test);
snippet('slider',['slider_id' => 'slider-'.$counter,'source' => $pagename]) ?>
</div>
</section>
<?php endif ?>
texnixe
4
What exactly do you mean? From where to where do you want to pass the variable?
Perry
5
From Home template to slider snippet.
Now it works with the $page->uid()
Thank you for helping.
<?php if($section->intendedTemplate() == "slider" ): ?>
<section id="<?php echo $section->title() ?>" class="article-wrapper">
<div class="content grid-col-96 flex align-content-space-between center">
<?php $counter++ ?>
<?php $page_uid = $section->uid() ?>
<?php $pagename = $site->find($page_uid) ?>
<?php snippet('slider',['slider_id' => 'slider-'.$counter,'source' => $pagename]) ?>
</div>
</section>
<?php endif ?>
snippet
<div id=<?php echo $slider_id ?>>
<div class='slider_nav'>
<a class="back" href=""></a>
<a class="next" href=""></a>
</div>
<?php
// Transform the comma-separated list of filenames into a file collection
$filenames = $source->slider_images()->split(',');
$filenames = array_pad($filenames, 2, '');
$files = call_user_func_array(array($source->files(), 'find'), $filenames);
// Use the file collection
echo '<ul class="flex">';
foreach($files->sortBy('sort', 'asc') as $file):
{
echo "<li><img src=".thumb($file, array('width' => 2000))->url()."></li>";
}
endforeach;
echo '</ul>';
?>
</div>