Posts module - meta description for individual post

joe - 2 months ago

Meta descriptions and keywords appear as fields on post entries, but do not show up on the page. I'm using <meta name="description" content="{{ trans(template.meta_description) }}"> to get meta descriptions on the main template.

I'm guessing it would show if I used: {{ }}

Would it be best to use an if statement in the template to see if that is set first, and then take the post one over the template meta, if it exists.. Or create a new template for posts?

piterden - 2 months ago

You should to try just {{ post.meta_description }} /core/anomaly/posts-module/src/Post/PostLoader.php

     * Load post data to the template.
     * @param PostInterface $post
    public function load(PostInterface $post)
        $this->template->set('title', $post->getTitle());
        $this->template->set('meta_title', $post->getMetaTitle());
        $this->template->set('meta_keywords', $post->getMetaKeywords());
        $this->template->set('meta_description', $post->getMetaDescription());


            'post'    => $post,
            'content' => $post->getContent(),

But its strange that not works with template.

ryanthompson - 2 months ago

@joe are you by chance using multiple languages? What are the values you have for description and meta description?

joe - 2 months ago

@piterden Will try that, I guess I can create another template if i cant get it to work with {{ template.meta_description }}.

@ryanthompson at the moment no other languages are used, but multiple languages are installed and ready to go for whenever the content is created.

Do you mean the actual values I've set? They are different for each post, but just a small summary for each, and I have <meta name="description" content="{{ trans(template.meta_description) }}"> in my main template which works for pages, but not posts. They also want me to add the og:image meta tag for posts (to show images when sharing).

Struggling a bit at the moment though as this error as appeared on my local copy (but not on live with identical code), when trying to view/preview posts: -ErrorException in Loader.php line 74: Illegal offset type in isset or empty - Twig_Error_Runtime in Template.php line 402: An exception has been thrown during the rendering of a template ("Illegal offset type in isset or empty") in "theme::posts/post" at line 1. I've checked the post file in my theme and its indentical to the code in the posts module, twig wise, so not sure what's happened :(.