Skip to content

Getting the First Paragraph in Page #129

Answered by taufik-nurrohman
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

Bisa sih pak. Ini di luar konsep Mecha sebenarnya. Di CMS apa saja bisa diterapkan. Tinggal mencari di sebelah mana kita bisa menerapkan kait ke konten artikel.

Hook::set('page.content', function($content) {
    $content = trim($content);
    if (str_starts_with($content, '<p>') || str_starts_with($content, '<p ')) {
        $parts = explode('</p>', $content, 2);
        $out = '<div class="headline">'
        $out .= $parts[0] . '</p>';
        $out .= '<p>';
        $out .= '<b>' . i('Author') . ':</b> ';
        $out .= '<span>' . $this->author . '</span>';
        $out .= '</p>';
        $out .= '</div>';
        $out .= ($parts[1] ?? "");
        return $out;
    }
    return $content;…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
x.page Page extension.
1 participant