Hi everyone. I am trying to do the following:
Each blog post is associated with a project. On the home/blog page, I would like to display a link to the project that corresponds with the blog posts.
So my blog article blueprint includes a field for the project:
project:
label: Project
type: tags
lower: true
width: 1/2
default: coolhouse
In my homepage, I have a snippet for an article, which is called like this:
foreach($rest as $article):
snippet('homepage_article', array('article' => $article));
endforeach;
The article snippet is this:
<? $project = $article->project()->value(); ?>
<article class="homepage-article grid-item <?= $project ?>">
<a href="<?= page('projecten')->find($project)->url(); ?>">
<h2 class="h4 homepage-article-title"><? echo $article->title()->html() ?></h2>
<? $image = $article->image();
if($image): ?>
<img src="<?= $image->url() ?>" alt="" class="homepage-article-image">
<? endif ?>
<?= excerpt($article->richtext(), 50, 'words') ?>
</a>
</article>
(Currently the entire article is wrapped in a link. This may change, but for now it’s okay.)
The problem is that I’m getting this error: Call to a member function url() on boolean
in the line <a href="<?= page('projecten')->find($project)->url(); ?>">
<?= $project ?>
outputs the actual project string (i.e. “Werf07” or something else.)
So how should I link to an assosiated project from a blog post?
Thanks!