Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

No numbers in the slug?

Started by Muut Archive 11 years ago · 10 replies · 647 views
11 years ago

Usually my URL for a post looks like this:

TXT
http://www.domain.com/25-important-keywords.html

Well, I managed, that there's no way to eliminate the /blog/ slug in Grav - if there is, please let me know ;)
I also have problems with the rest. I use the slug: variable in item.md to change the slug the way I want. The .html works fine for me. But if I use numbers in the slug, they don't show in the URL.

Usually the number is the ID for the post (which is good for search engines). But since there's no way to use numbers in the slug, blog posts like »10 ways to strenghten your self confidence« wouldn't work either.

Is there a workaround for that? Didn't found anything in the documentation.

11 years ago

blog/ is there because the blog posts are subpages of the blog page.
You could add the posts as top-level pages, but then you'd need to rewrite their templates, and the homepage template to list them.

I just tested, the numbers in the slug (e.g. slug: 10-test) work fine.

11 years ago

Well, if the blog page weren't the home page, blog/would be fine. But so it's not very logical ;)
I just tested it again... First 10-test.htmlworked, but 1-test.htmldoesn't (404 error). I cleared the cache several times, now only test.htmlworks, but I get a 404 again on each number I test.

11 years ago

The slug will use the folder name of the page by default. It automatically strips out any numbers in the formation XX. (ie. XX.folder-name). So the resulting slug for a page in 03.folder-name will be /folder-name.

If you wish to have a numeric in the slug, then you should create your folder like this 10-test/ then you put your default.md or post.md in that folder.

This default.md is named to referenced the default.html.twig template file from the theme to render the page. This is not related to the slug!

Hope that makes sense!

11 years ago

I didn't touch the folder name at all. It's like this:

TXT
01.blog/
    this-is-the-title/
        item.md

I added a slug: variable in the item.md instead, like this:
--- yaml
title: This is the title
slug: 1-this-is-the-title.html

TXT

Without the number it works well with this method ;)
11 years ago

So i'm confused, it's not working with: slug: 1-this-is-the-title.html or it is?

11 years ago

Actually what you can do, rather than use a slug override, you can simply use a route alias:

YAML
routes:
   aliases:
      - '/1-this-is-the-title'

This should let you reach /blog/this-is-the-title as /1-this-is-the-title. The .html on the end should work without any extra config.

11 years ago

Yes, of course, but only without the numbers. slug: this-is-the-title.htmlworks perfectly fine ;)
Aliases aren't an option for me... I start with about 150 blog posts. So I would start with 150 aliases and any other blog post would need another alias.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1348 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago