Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excerpt and Description #6

Closed
mrmlnc opened this issue May 18, 2014 · 4 comments
Closed

Excerpt and Description #6

mrmlnc opened this issue May 18, 2014 · 4 comments

Comments

@mrmlnc
Copy link
Contributor

mrmlnc commented May 18, 2014

Hi RainLab, Prompt how to display the contents of the "Excerpt" in "meta=Description" on page post?

@alekseybobkov
Copy link
Contributor

Hi, try this:

{{ blogPost.excerpt }}

@alekseybobkov
Copy link
Contributor

Sorry, I just realized that you wanted to know how to display it in the meta tag. There is a solution for it. Use the onEnd() function in the page PHP section to access the loaded post object. Load the excerpt from the post and inject it to the page as a new variable:

function onEnd()
{
    if (isset($this['blogPost'])) {
        $this->page->title = $this['blogPost']->title; // Example - override the page title
        $this['metaDescription'] = $this['blogPost']->excerpt;
    }
}

Example page (or layout) HEAD tag contents:

<head>
    ...
    <title>{{ this.page.title~' - October CMS' }}</title>
    <meta name="description" content="{{ metaDescription }}">
    ...
</head>

@mrmlnc
Copy link
Contributor Author

mrmlnc commented May 18, 2014

Thanks Aleksey. It works.

@domagoj03
Copy link

If I'm using
{% component 'blogPost' %}
on Markup side to render it's contents, how can I access it in Code section on the same page?
in onEnd() function isset($this['blogPost']) returns false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants