I am in the process of learning Node.js/Express.js, and as an experiment I am attempting to build a small blog application.
I render the page, passing the articles:
response.render('index.jade', {
title: 'Blog'
, locals: {
articles: articles
}
});
Here's my Jade template for that:
h1= title
section
h1 Articles
ul
each article in articles
li
a(href='/article/' + article.slug)= article.title
span at #{article.created_at}
This displays a list of articles with the title and date. However, I need a way of formatting the date into a more readable format. I have discovered libraries that allow you to do this, but my real question is how I should go about integrating this into my template? I can either pass the moment module to the template and format the date inline there, or I can format it in the route and add it onto the article object. How would you do this?
I have the following helpers in my application:
date: function (date) {
return moment(date).format('YYYY/MM/DD HH:mm:ss');
},
fromNow: function(date) {
return moment(date).fromNow();
}
This could depend on your application but I didn't see the need of using different date formats all over my site.
I would go with adding to the template if you want less and clean code. If you want performance, format it in the route itself.
Related
I'm making a website with Hakyll. I successfully created a RSS feed showing showing for each post the teaser section delimited by <!--more-->.
My problem is that this teaser section is shown in the full (templated) pages of these posts. And I would like only that is after <!--more--> and not before.
---
title: My Post
author: JeanJouX
date: 2016-09-06
tags: Haskell
---
The teaser of my post to be shown in the RSS feed. Not in the full page.
<!--more-->
The rest of the post to be shown in the full page of my website
Is it possible to do that with Hakyll?
I don't believe there is a method to do that built into Hakyll.
As I see it you have two options:
write a pass that strips the teaser from the document before rendering it on its own page
keep the teaser in the actual page, but use CSS to hide it
The first option is probably better, but requires mussing about with string manipulation and Hakyll compilers. If you want a place to start, take a look at the implementation of teaserFieldWithSeparator which uses the needlePrefix function from Hakyll.Core.Util.String to extract the teaser from the document body. You'll have to do the opposite: extract everything but the teaser.
If you do take this approach, you could contribute it back into Hakyll, saving the effort for people who want to do the same thing in the future.
The other option is hackier but easier. You can wrap all your teasers in a div with some CSS class:
<div class="teaser">
Some text.
</div>
<!--more-->
Then, in your page template, add a CSS rule that hides the teaser paragraph:
.teaser {
display : none;
}
The text is still in the page's HTML so this is not an ideal solution, but you can make it work without needing to write any Hakyll code.
Maybe it could be easier if you just put this teaser text in a separate metadata field? Like
---
title: My Post
author: JeanJouX
date: 2016-09-06
tags: Haskell
description: The teaser of my post to be shown in the RSS feed. Not in the full page.
---
The rest of the post to be shown in the full page of my website
Then you don't need to make that teaserField any more. You already have all you need in $description$, which you can use in rss, in html meta tags, anywhere.
I'm attempting to add an image to a page type using a singleton set to the slideshow widgetType
The interface is working fine (can upload image, limits uploads to the set variable), but I cannot access the object in the templates
I am logging the page object with the below script in the page template, every other custom field works fine, just not the slideshow widget.
var data = {{ page | json }};
console.log(data);
Here is what is set in app.js
project: {
extend: 'apostrophe-fancy-page',
name: 'project',
label: 'Project',
addFields: [
{
name: 'thumb',
label: 'Thumbnail',
type: 'singleton',
widgetType: 'slideshow',
options: {
limit: 1
}
}
]
}
Any advice?
Hmm. You don't specify, but my suspicion is that you're trying to access the thumbnail from the template for a different page that has access to it as related-page information, e.g. page.ancestors or page.children. If the singleton were being rendered on the template for the page itself, you would have no trouble with this.
The thing about related-page information is that for performance reasons, Apostrophe limits how much information it includes in those arrays.
However, you can specify that you want more information. Here is an example from the pages property of the app.js file of one of our projects:
pages: {
// other config like page types goes here, then...
ancestorOptions: {
children: true,
areas: [ 'thumbnail' ]
},
descendantOptions: {
depth: 2,
areas: [ 'thumbnail' ]
}
}
Here we are enabling:
Include a .children array for each ancestor in page.ancestors, for accordion nav
Include the area called thumbnail for each ancestor
Include the area called thumbnail for each child of the current page (page.children)
Also include grandchildren page.children[0].children for dropdown nav
When you load more data, the price you pay is a little more time. This is a good compromise setup when you need a lot but you don't want to fetch thousands of pages and "hydrate" all of their widgets by fetching even more data.
If I'm mistaken and you are doing this on the page template for the page itself and it still doesn't work, please provide some examples and I can review those.
(I am one of the lead developers on Apostrophe. Apologies for not seeing this question sooner. StackOverflow is a good place for it and we'll be monitoring more closely in the future now that 2.0 stable has been released.)
The title pretty much sums it up. I created my own module in Orchard. I can access its actions via http requests like an ordinary controller in any MVC application.
I generated the controller using the command line interface and it came with IOrchardServices property that is populated in the constructor.
On my Orchard site I have a blog which I filled up with about 40 blog posts.
How can I query these blog posts from within my controller?
First I would like to start by saying: "read the source luke". You may find Orchard lacking in documentation and examples, but because it is open source, pretty much everything you want to know can be found there.
You should use the BlogPostService, inject that into your controller to get the blog posts you want.
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs
You can see it being used in several controllers within Orchard.Blogs:
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs
Check out the code in the BlogPostService to see how it works, it is a little confusing because blogs are content items with blog posts underneath them. If you want to learn about simpler querying of content items I would check out how the BlogService works, it is a little easier to get to grips with:
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs
Here is an example of what I was looking for:
var query = Services.ContentManager.Query();
var list = query.ForType(new []{"BlogPost"}).List();
var result = new List<dynamic>();
foreach (var contentItem in list) {
result.Add(new
{
title = contentItem.As<TitlePart>().Title, // dynamically typed: ((dynamic)contentItem).TitlePart.Title
text = contentItem.As<BodyPart>().Text
});
}
I'm fairly new to Orchard and I'm wondering about the "best" way of building a basic list of documents with a download link?
Say the scenario is this, I want to make a list of newsletters, the news letter are in PDF format and the users should be able to download then straight from the list view.
An admin, should easily be able to add a new newsletter and it should turn up in the list.
My current train of thought is to, all through the dashboard,
create a content type "Newsletter" with a title field and a Media picker field, using the media picker field to upload the PDF file.
Then create a query, with the filter on Content type "Newsletter"
Create a projection pointing to the query
However, this only gives me a list of content items, showing their title as links back to the actual content item.
I've tried adding a layout to the query and set it to display properties instead of content. By doing that I can get a list where I can control the "output" a bit more. And I've gotten it to list the title and by doing a Rewrite and putting in the MediaPicker.Url, it also displays the URL in the list. This is all good but here I get stuck..
As the MediaPicker.URL outputs the url in the format like ~/media/default/xyz/filename.pdf, I cant just put it into a a href, it doesn't give a correct download link to the file.
Soo, question is, am I thinking and doing this totally the wrong way or am I missing something obvious? All ideas and suggestions and more then welcome.
Use or adapt the following template override in your theme:
#{
var url = Model.ContentField.Url;
}
#if(Model.ContentField.Url != null) {
if (url.StartsWith("~/")) {
url = Href(url);
}
<div class="media-picker-field attachment-pdf">
<span>download</span>
</div>
}
Modify the text as needed. This template was a Fields.MediaPicker-PDF.cshtml that was used for a media picker field named PDF.
In Liferay I have used the asset publisher to publish news on my news page. I want to fetch the 3 top news from the page and embed it into another page. How can I do this? The page URL containing the news links looks like the following:
Liferay.Widget({ url: 'http://test.com/testnews/101_INSTANCE_f22'});
Liferay itself has a property where one can share an asset publsiher instance any where else on a site, but that is not exactly what I want. So any help or guidance is appreciated. Thanks.
If you want only links then you can set display style 'title-list' (this will take you to the article on the main news page).
if you want to open the link in another page, change asset link behavior to 'View in a specific portlet'.
You can change the look of asset publisher to whatever design you want. follow the path look & feel --> advanced styling --> Copy the portlet id. Now by using mozilla firefox pick the class,tags,etc. and write your css code. This will override the basic design. E.g.
#p_p_id_101_INSTANCE_8f5JPIxv8ml0_ .asset-abstract {
width: 25%;
float: left;
}
Is there a particular reason why you don't want to configure another AssetPublisher on the second page? You can just use the identical configuration, but limit the number of results shown to 3 - done.
Problem solved. Here is the solution with jQuery:
$.get('http://test.com/news/', function(data) {
var top3links = $(data).find('a:lt(3)');
$('#top3').html(top3links); // });