How to internal linking to blog post

I’m using the internal linking within the markdown editor:
[Post](october://entry-edcd102e-0525-4e4d-b07e-633ae6c18db6@link/173?cms_page=blog%2Fpost)

CMS Page setup of the Blog Post:

url = "/:category/:subcat/:slug"
layout = "blog"
title = "Blog Post"
meta_title = "{{ blog.title }} - Blog"

This is how I render the markdown content

{% if post.entry_type == 'markdown_post' %}
  {{ post.content|md|content }}
{% else %}
  {{ post.content|content }}
{% endif %}

Output link to blog post:
http://localhost:8888/site/en/default/default/whv-australia

I’ve tested to internal link directly to a category.
Output link to category:
http://localhost:8888/site/en/oceania/australia

And apparently, this issue is in the Sitemap as well (link to )

Does anyone know how to solve this?

Hey @kevinvermeulen

We’ve added a solution to this in v3.6.1

In the provided example, you could add the following to your blueprint:

pagefinder:
    replacements:
        subcat: categories.0.slug
        category: categories.0.parent.slug

The above selects the first category for subcat and the first categories’ parent as the category. It will still return “default” if the category has no parent…

So a better approach might be to use a wildcard URL along with a structure for the categories to enable the fullslug attribute that builds a slug containing a path back to the parent category.

url = "/:category*/:slug"

Then in YAML

pagefinder:
    replacements:
        category: categories.0.fullslug

Here is the relevant documentation, I hope this helps!


Page Finder Configuration

The page finder will automatically resolve the id, code, slug and fullslug attributes and use them as replacements in the page URL parameters. You may specify custom replacements as an array using the pagefinder properties, including the optional context from above.

pagefinder:
    context: list
    replacements: []

Each replacement key should match a URL parameter name and use a dot notation path to the attribute value. Take the following URL example for a blog post page.

url = "/blog/post/:author/:category/:slug/:id"

The following replacements will set the :author parameter to the related author slug attribute value, and the :category parameter to the first related categories slug attribute value.

pagefinder:
    replacements:
        author: author.slug
        category: categories.0.slug
1 Like

Thanks for the reply. Yes this makes really sense and very helpful!

I added the replacements (both ways as described) in the Blueprint of the Sitemap (demo theme) in OC 3.6.2.
Unfortunately, it doesn’t allow me to do it as I get an error. Also I tried in the top of the Blueprint unsuccessfully under pagefinder.

uuid: 6743a1c3-3e57-4cfa-a886-e0c0a277fd71
handle: Site\Sitemap
type: structure
name: Sitemap
drafts: false
pagefinder: false 

uuid: 6743a1c3-3e57-4cfa-a886-e0c0a277fd71
handle: Site\Sitemap
type: structure
name: Sitemap
drafts: false
pagefinder: false      

structure:
    maxDepth: 1

navigation:
    parent: settings
    icon: icon-sitemap
    description: Specify pages to appear in the sitemap for your website.
    category: CATEGORY_CMS

fields:
    reference:
        label: Reference
        type: pagefinder
            replacements:
                subcat: categories.0.slug
                category: categories.0.parent.slug
        

    priority:
        label: Priority
        commentAbove: The priority of this URL relative to other URLs on your site.
        type: radio
        inlineOptions: true
        options:
            '0.1': '0.1'
            '0.2': '0.2'
            '0.3': '0.3'
            '0.4': '0.4'
            '0.5': '0.5'
            '0.6': '0.6'
            '0.7': '0.7'
            '0.8': '0.8'
            '0.9': '0.9'
            '1.0': '1.0'

    changefreq:
        commentAbove: How frequently the page is likely to change.
        label: Change Frequency
        type: radio
        inlineOptions: true
        options:
            always: Always
            hourly: Hourly
            daily: Daily
            weekly: Weekly
            monthly: Monthly
            yearly: Yearly
            never: Never

    nesting:
        label: Include nested items
        shortLabel: Nesting
        comment: Nested items could be generated dynamically by supported page references.
        type: checkbox

    replace:
        label: Replace this item with its generated children
        comment: Use this checkbox to push generated menu items to the same level with this item. This item itself will be hidden.
        type: checkbox
        column: false
        scope: false
        trigger:
            action: disable|empty
            field: nesting
            condition: unchecked

Hey @kevinvermeulen

The replacements go on the linked blueprint. So if you are linking to a Blog\Post

uuid: edcd102e-0525-4e4d-b07e-633ae6c18db6
handle: Blog\Post
name: Post
type: stream

pagefinder:
    context: item
    replacements:
        category: categories.0.slug
        subcat: categories.0.parent.slug

fields: []

:pray:t3: Thanks a lot mate!
This is working perfectly and was the missing link for me.

I really enjoy working with OC especially with Blueprints nowadays!

1 Like

My pleasure. That’s great to hear as well :slight_smile:

1 Like