Hello,
Sorry in advance if it is more a php beginner question than a kirby question.
I’m would add a different content in the span, depend if subpage comes from projets or blog, and I tried several way but was not able to do it…
Here is the last way I tried to do it 
Thank you for your help,
Constant
<ul class="liste">
<?php foreach($pages->find('projets' , 'blog')->children()->limit(9)->shuffle() as $article): ?>
<li>
<div class="content">
<h2><?php echo html($article->title()) ?></h2>
<p><?php echo $article->text()->excerpt(110) ?></p>
<span class="test"><?php if($article->isProjetsPage()): ?> test1 <?php else: ?> test2 <?php endif ?></span>
<a href="<?php echo $article->url() ?>">Visitez <?php echo $article->name() ?></a>
</div>
</li>
<?php endforeach ?>
</ul>
If I’m not mistaken, I think you could use:
$page->isChildOf($parent)
Like this:
<ul class="liste">
<?php foreach($pages->find('projets' , 'blog')->children()->limit(9)->shuffle() as $article): ?>
<li>
<div class="content">
<h2><?php echo html($article->title()) ?></h2>
<p><?php echo $article->text()->excerpt(110) ?></p>
<span class="test"><?php if($article->isChildOf('projets')): ?> test1 <?php else: ?> test2 <?php endif ?></span>
<a href="<?php echo $article->url() ?>">Visitez <?php echo $article->name() ?></a>
</div>
</li>
<?php endforeach ?>
</ul>
You can also use the e()
function to simplify your if
inside the <span>
.
<span><?php e( $article->isChildOf('projets'), 'test1', 'test2' ) ?></span>
By the way isProjetsPage()
is not a method that exists in Kirby.
Hi, thank you for your reponse, unfortunatly I can’t make it work with :
$page->isChildOf($parent)
For the isProjetsPage()
I thought I could try to do the same as homePage and ErrorPage.
It should be $article->isChildOf(page('projets'))
, because the parameter is a page, not a string.
These two are the only special cases. But if you want to check by template, you can do this as well:
<span><?php e($article->template() == 'blogpost', 'test2', 'test1'); ?></span>
That’s it! Thank you for your help and explication. And very good to know how to do with templates also.