Skip to content

getContent() does not process Blade files #172

@imsus

Description

@imsus

Currently the $page->getContent() function only allows markdown files to be rendered.

Why?

I've got a content like this:

---
extends:
  web: _layouts.post
  amp: _layouts.amp
  feed: _partials.feed-item
title: My First Blog Post
date: 2017-03-23
section: content
---

This post is *profoundly* interesting.

@include('_partials.image', ['src' => 'https://source.unsplash.com/random', 'alt' => ''])

If you curious about what does the _partials.image.blade.php does, it just switching between img tag and amp-img tag for amp-html templates.

@switch($page->_meta->extending)
    @case('instant-articles')
        <figure data-feedback="fb:likes, fb:comments">
          <img src="{{ $src }}" alt="{{ $alt }}">
          @if($caption ?? false)
            <figcaption>
              <h1>{{ $caption }}</h1>
            </figcaption>
          @endif
        </figure>
        @break
    @case('amp')
        <figure>
          <amp-img src="{{ $src }}" alt="{{ $alt }}"></amp-img>
          @if($caption ?? false)
            <figcaption>Caption</figcaption>
          @endif
        </figure>
        @break
    @default
      <figure>
        <img src="{{ $src }}" alt="{{ $alt }}">
        @if($caption ?? false)
          <figcaption>Caption</figcaption>
        @endif
      </figure>
@endswitch

Problems

The problem arise when I want to output the article into feed. When I use $page->getContent(), it doesn't render the blade directive.

feed.blade.json

{
  "user_comment": "This is a JSON Feed. A modern alternative of RSS.",
  "version": "https://jsonfeed.org/version/1",
  "title": "{{ $page->blogTitle }} Feed",
  "home_page_url": "{{ $page->baseUrl }}",
  "feed_url": "{{ $page->getUrl() }}",
  "items": {!! $posts->map(function($item) {
    return [
      'id' => $item->getUrl('web'),
      'content_html' => $item->getContent()
    ];
  })->values() !!}
}

Leaving the code like this:

feed.json

{
  "user_comment": "This is a JSON Feed. A modern alternative of RSS.",
  "version": "https://jsonfeed.org/version/1",
  "title": "Imam Susanto Blog Feed",
  "home_page_url": "http://localhost:3000",
  "feed_url": "http://localhost:3000/feed.json",
  "items": [
    {
      "id": "http://localhost:3000/blog/my-first-blog-post",
      "content_html":
        "<p>This post is <em>profoundly</em> interesting.</p>\n<p>@include('_partials.image', ['src' =&gt; '<a href=\"https://source.unsplash.com/random\">https://source.unsplash.com/random</a>', 'alt' =&gt; ''])</p>"
    },
    {
      "id": "http://localhost:3000/blog/my-second-blog-post",
      "content_html":
        "<p>This post is <em>profoundly</em> interesting.</p>\n<p>@include('_partials.image', ['src' =&gt; '<a href=\"https://source.unsplash.com/random\">https://source.unsplash.com/random</a>', 'alt' =&gt; ''])</p>"
    }
  ]
}

Is it possible that blade files also included? So that files like post.blade.json or post.blade.xml will get the same treatment.

Thank you for reading this issue. Hope it helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions