How to define default taxonomy for a page type in Grav CMS? - grav

In my current Grav project, I am trying to display the newest 5 posts of a specific type. For the purposes of this question, let's just call the post type 'book.'
I'm aware that this would be much easier if I simply made a page called "Books" and made every 'book' a child of that page, but the individual who will be using this website isn't particularly computer literate and is already finding the admin plugin interface daunting. I imagine there could be multiple instances where they would create a 'book' post and forget to assign it as a child of "Books."
So as a result, I decided that I would just set a default tag for the 'book' pages and use that taxonomy to create a page collection that I could just iterate over, that way, regardless of where the page is put, it will still be in the collection.
The problem is that I can't seem to figure out how to set a default value for the taxonomy field type in the admin plugin.
I have attempted the following in my book.yaml file:
header.taxonomy:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
multiple: true
default:
tag:
- Book
validate:
type: array
header.taxonomy:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
multiple: true
default:
- tag:
- Book
validate:
type: array
header.taxonomy:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
multiple: true
default: {tag: [Book]}
validate:
type: array
I'm not sure what to do in this case, as the existing documentation doesn't seem to offer much in the way of help. Am I putting the default in the wrong place? Am I defining it in the wrong way? Is what I want to do even possible?

I have managed to find the solution to my own dilemma.
header.taxonomy.tag:
type: selectize
label: Tag
classes: fancy
default: Book
validate:
type: commalist
I'm not sure why this is the case, but this does not work without 'classes: fancy'

Related

No permalink in Eleventy

I'm migrating from Jekyll to Eleventy, where previously my blog post links had the permalink in this style: /:title/
What I want: https://example.com/my-blog-post/ for posts/my-blog-post.md
What I get: https://example.com/posts/my-blog-post/ for posts/my-blog-post.md
How can I configure this in Eleventy? The official page on 11ty docs says it takes the name of the folder, which is posts in this case.
I want this /:title/ for all my markdown files. I can't manually set the permalink in all my files. Is there a way to do so for the entire posts collection?
I'm using this repo as the base theme.
So after searching a lot (not the docs), I finally found the solution in this article.
In the last part of that section, use this:
// posts.json (or whatever your collection name is)
{
// ...
"permalink": "/{{ title | slug }}/"
// ...
}
Excerpt:
Using directory data to manage defaults
By default, Eleventy will maintain the structure of your content files when generating your site. In our case, that means /_basic-syntax/lists.md is generated as /_basic-syntax/lists/index.html. Like Jekyll, we can change where files are saved using the permalink property. For example, if we want the URL for this page to be /basic-syntax/lists.html we can add the
following:
---
title: Lists
syntax-id: lists
api: "no"
permalink: /basic-syntax/lists.html
---
Again, this is probably not something we want to manage on a file-by-file basis but again, Eleventy has features that can help: directory data and permalink variables.
For example, to achieve the above for all content stored in the _basic-syntax folder, we can create a JSON file that shares the name of that folder and sits inside it, i.e. _basic-syntax/_basic-syntax.json and set our default values. For permalinks, we can use Liquid templating to construct our desired path:
{
"layout": "syntax",
"tag": "basic-syntax",
"permalink": "basic-syntax/{{ title | slug }}.html"
}
You can set up permalinks per page or per collection. Assume you create a posts folder, then add a posts.11tydata.json file with content to set up basic values for a collection.
{
"eleventyExcludeFromCollections": false,
"layout": "post",
"permalink": "post/{{ title }}/",
"tags": [
"posts"
]
}

Bigcommerce Stencil declare custom front-matter variable

I would like to define a list of featured category IDs within my homepage template. Is it possible to define a custom variable in the front matter? I can't seem to get it working:
Here is the default front-matter in templates/pages/home.html with my custom variable, featured_categories at the end:
---
products:
new:
limit: {{theme_settings.homepage_new_products_count}}
featured:
limit: {{theme_settings.homepage_featured_products_count}}
top_sellers:
limit: {{theme_settings.homepage_top_products_count}}
carousel: {{theme_settings.homepage_show_carousel}}
blog:
recent_posts:
limit: {{theme_settings.homepage_blog_posts_count}}
featured_categories: 'testing'
---
Then, in the template, this line is not producing any output:
{{featured_categories}}
Why doesn't this output the value testing? Ultimately, I would like featured_categories to be an array of category ID's. Is this possible to do using front matter?
It is not possible to declare a custom front matter variable as those have to be determined in the framework by BigCommerce. You can import handlebars yourself and define a variable, but it would execute client side and not server side for security reasons.

How to generate SEO friendly URLS using flow router?

I am working on an application that needs to have some SEO standing. For starters it would be nice to get slug type search engine friendly urls that get generated based on document title. Does anyone know of any libraries or ways to get about doing that?
Secondly based on my reading it seems that if one wants better SEO that he/she get iron router since there are some 3rd party packages that seem to help with that (spiderable etc). Also iron router is easy with generating titles and meta tags. Is that a true assumption?
If you use simple schema then you can do something like this:
Posts.attachSchema new SimpleSchema
title:
type: String
content:
type: String
url:
type: String
autoValue: ->
title = #field('title')
unless title.isSet then return
someEscapeFunction(title.value.substring(0, 120))
and pass url as path param in router

Meteor 1.0 - Passing a parameter into pathFor using iron:router

I've seen a few answers on how to pass a parameter using iron:router as the third parameter, for example: href="{{pathFor 'article' _id=this._id }}"
What I would like to do is pass a parameter as the second variable (where 'article' is in the example above).
I have a collection of posts that contain a title, a body, and a type. There are three types of articles in the project I'm working on, and each type needs to be routed to a different template because the formatting is significantly different.
What I would like to be able to do is route to a particular url based on the type. An example that captures my intent but doesn't work would be this:
link
One of the "types" is "inquiry", and the route looks like this:
#route "inquiryPost",
path: "inquiry/:_id"
data: ->
Posts.findOne #params._id
waitOn: ->
[
Meteor.subscribe "posts"
]
I've tried using a helper to pass the value into the pathFor, but that didn't work either:
path: ->
type = #type
"pathFor '#{type}'"
...with this on the front end:
link
I can think of a few work arounds, but it seems to me like there should be an easier way to pass in parameters...
So, is it possible to pass in parameters into the second value of a pathFor?
Try with
<template name="example">
link
</template>
Where type is the helper
Template.example.examples({
type:function(){
return type;
}
})
Also you can try with this for example
link with many parameters
Here you where accessing for example to the route
/myRoute/type/rewr8671qew for example

How to enable siteEdit for Embedded Fields when using DD4T?

I am trying to enable siteEdit for the Embedded fields for the pages implemented using DD4T.
I am able to find the methods and tags which helps to enable it for normal methods and component presentation but not for Embedded Fields and at the components(directly passing the Icompoennt model) level.
I am trying to enable it for SiteEdit2012(UI)
Please help.
The same as a 'normal' field. Imagine you have an embedded field called 'address' with 2 fields: street and number. This is how you would make it !SiteEdit enabled:
//Street
#Html.SiteEditField(Model.Component, Model.Component.Fields["address"].EmbeddedValues[0]["street"])
//Number
#Html.SiteEditField(Model.Component, Model.Component.Fields["address"].EmbeddedValues[0]["number"])

Resources