My site has a collection of research reports, which renders out as a page for each report that includes a link to a PDF, like a standard directory based Eleventy collection. For one of the reports, I'd like to add the full report as HTML pages, which each section, e.g. Methodology, as it's own sub page.
In other words, I'd like to have sub pages for a page in a collection.
Could anyone provide advice on how I might do this with Eleventy?
Thanks a million <3
You can use Pagination like so:
---
pagination:
data: page.subArray
size: 1
alias: subData
permalink: "subpage/{{ subdata.title | url }}/index.html"
---
You can then access the data for each sub page via the {{ subData }} alias
Related
All the documentation I've found on Eleventy pagination has to do with a single level, and I've got that working pretty well.
Take a collection (ex. of tags) and create one page each
Take a collection of posts and put 10 on each page
and so on.
What I'd like to do now is combine them: loop over all the tags, and then paginate each tag's collection so if I use some tags a lot, they don't end up with 50 posts on the same page. Basically the way WordPress generates paginated views for each tag.
Something like this: (simplified, I know filters need to be in there)
pagination:
data: collections
size: 1
alias: tag
pagination:
data: tag
size: 10
alias: tagpost
Though that didn't seem to work.
Is there some way to do multi-level pagination, or would I need to take some other approach for the outer loop?
That has been the thorn in my side from the beginning. There is an issue post on 11ty's GitHub explaining how to flatten the data and then paginate using Javascript, but then you'll lose all the nice pagination features already built in 11ty.
Another big issue is how to get Tags dynamically from the API. If you need a single template file for each Tag, paginated or not, you have to do it manually for each tag. So if there's a new tag coming from CMS through API 11ty has no way to handle it automatically.
There are a zillion tutorials for 11ty and not a single one explaining how to do two things that literally every site needs to have.
Good luck with it.
BTW, that being said, I love 11ty, I really do.
You can build a custom collection
config.addCollection("tagpages", function(api) {
// Map over api.getAll() to build TagPage or TagGroup that contains
// an array of Pages
});
that has the format:
TagPage {
id: Number;
tag: string;
posts: post[];
}
Then the front matter:
---
Pagination:
Data: collections.tagpages
Size: 1
Alias:tagpage
Permalink: /{TagPage.tag}/{TagPage.id}
---
Display your tag and X posts.
You could have your config customize by tags and number of items per page.
config.addCollection("tagpages", buildTagPages(tag, numItems));
I have a simple model for blog posts with a TextField, I save my posts in html format via Django admin interface. But my posts often include hyperlinks to other blog post pages like click here, the number and target of links in a post vary. What is the easy way to insert those urls dynamically in Django admin panel (like template tags used in templates)?
I found an answer, I think this can be done with using builtin url tags like {% url 'blog:posts' 123 %} in my text, saving the text as a template and rendering it again. Either in the view or in the template with a custom template filter.
Is it possible to change the layouts such that eleventy generate a set of markdown format files?
I have a list of authors from a library catalogue which I want to continue edit them to make a single page for each of the author. So I want to generate a markdown template for each record first, then I will continue edit these one by one.
You can use Eleventy and templating to generate a variety of file types, including Markdown. Essentially, if you have text and want to use templating languages to generate it, Eleventy can do that.
For example, let's say you have a global data file containing fruit names. This could also be an array of objects, but for simplicity let's just use names for now. In your case, this could be an array of objects for each author.
// _data/fruits.js
module.exports = [
'Apples',
'Bananas',
'Oranges',
'Pears',
]
You want to create a Markdown page for each fruit with a little description. In this example, I'll be using Nunjucks but this could be adapted to any templating language supported by Eleventy.
In fruits.md.njk (name doesn't matter):
---
pagination:
data: fruits
size: 1
alias: fruit
permalink: 'fruits/{{ fruit | slug }}.md'
---
--- {# We can even define front-matter that will appear in the output #}
layout: content
---
# About {{ fruit }}
{# Use whatever markdown syntax you want #}
{{ fruit }} are _very_ **delicious**.
`Buy {{ fruit }} here!`
In this template, we are using pagination to create individual pages for each item in the fruits array (paging global data). We define a permalink to output a .md file, and the rest of the file is just normal Markdown, with added templating tags. You can use all of the regularly available Nunjucks/other templating tags, such as loops, macros, or inheritance.
You can extend these ideas to generate other things, like Javascript files, JSON files, YAML files, XML, or any file that's just text. Nothing is stopping you from templating things that aren't HTML.
The output of the above template is:
---
layout: content
---
# About Apples
Apples are _very_ **delicious**.
`Buy Apples here!`
My application is developed in the laravel and am using render() function to display pagination in the listing pages but how will I show the current start and end record count wiht the pagination. Basically I want this before my pagination
Viewing 21 - 40 of 50 entries
Documentation is not complete about Paginator. You may use the appropriate methods from Illuminate\Pagination\Paginator :
Paginator::firstItem()
Paginator::lastItem()
and from Illuminate\Pagination\LengthAwarePaginator :
LengthAwarePaginator::total()
In your view, you may have something like this :
Viewing {{ $results->firstItem() }} - {{ $results->lastItem() }} of {{ $results->total() }} entries
Sometimes, you need to dive into the code to see if what you need can be easily achieved.
In the documentation, I noticed that JSON from Paginator had "from" and "to", so they had to be calculated somewhere... Which is actually the case.
1)i think Laravel 5.1 documentation will solve your problem.
http://laravel.com/docs/5.1/pagination.
2)and this site has shown an easy way to get you started.
http://tutsnare.com/how-to-create-pagination-in-laravel/
So this is what I'm trying to accomplish, but I'm not sure where to start:
I have the following structure of pages:
On the home page, I want to display each child to of Publications as a section. The two sections would be Alerts, and New Story of the Week. Then the latest published child of a section would render within that section. So on home page I would have the following sections and articles:
Alerts -> Trouble in the East-1-20-2015
News Story of the Week -> Congress Ohverhauls Farm Bill
I've read the CMS wiki, but I don't know how to approach this. Do I use tags and collections?
You'll need to create a partial to get this working.
Create one here /app/views/comfy/cms/content/_section_list.html.erb
Then in the layout for the homepage add {{cms:partial:section_list}} to the html where you want the partial to be displayed.
Then in _section_list.html.erb do something like:
<% #cms_page.children.each do |section| %>
<h1><%= section.blocks.where(identifier: 'header').first.content %></h1>
<%= section.children.first.blocks.where(identifier: 'content').first.content %>
<% end %>
Note: be sure to get the block identifiers correct, I'm assuming you have a header and content in the snippet above.
In cms layout that Publication is using define a partial tag {{ cms:partial:foo/bar/articles }}
Inside that partial you'll have access to #cms_page. Now you can render things out.
#cms_page.children will give you Alerts and News Story of the Week pages. Then you can fetch a first child of those pages.
It's using acts_as_tree in the back, so it's pretty straightforward.