How to get the post author data to display it in an html box? - velo

I'm not very used to working with Wix and I realized that it has a certain limit regarding the Blog layout. I would like to add the author of each post next to the post, but it would be too much work to do post by post.
So I created an HTML box to get the image and name of the author of the post. But I know I'm not doing it right. See:
Looking in the documentation the most I found was the function getPost() which returns various information from the post page, but 'author' or 'writer' is not among them.
My question is: is there any way to get the author data to display it in this box? Or, is there a simpler way to get to this desired layout?
Author information doesn't necessarily need to be inside an HTML box, if there's another way to do that, that's fine too!!

As seen on https://www.wix.com/velo/example/custom-post-page
You can get the ID of the post - which you already demonstrated you know how to do via getPost() then use that ID to retrieve the extra post data - which includes the currentPost.author entity that you are looking for. You can also see on the same page how this, and other data from that extra post data, can be brought into the page:
function assignPostDataToUIElements() {
$w("#authorName").text = `Written by: ${currentPost.author}`
}
User #Arnon De Paula definitely pointed us in the right direction with their link and should receive the bounty if this ends up being the answer you were looking for.

Related

Google Places API setFields AND getDetails

The google places api docs clearly state: "IMPORTANT: To avoid paying for data that you don't need, be sure to use Autocomplete.setFields() to specify only the place data that you will use." But then when I'm calling the getDetails() method (see in generic-y form below), I'm specifying my fields, which is what setFields() sets.
I THINK I'm basically setting them via the getDetails() method, but given the caution exercised in the docs, I also don't want to surprise anyone with extra costs besides what we need. I've tried to find a clear answer in the docs, but I haven't found one. I'm hoping someone here knows from experience or has better luck with the docs. Thanks!
const placesService = new google.maps.places.PlacesService(myField);
placesService.getDetails(
{
fields: ['address_components'],
placeId: result.place_id,
sessionToken: token,
},
details => this.updateMethod(details.address_components),
);
Autocomplete.setFields is used when implementing Places Autocomplete Widget which will constrain the succeeding Places Details request to specific fields only when a user selects a place from the suggestions. Check out the example here.
However, as for your given sample code, I can see that you are directly using Places Service to get the details of a place given a Place ID and not from the Autocomplete Widget suggestions. With this, you can just set the fields in the request parameter of the getDetails(request, callback) method which is what you have correctly done in your code. See this example.
Hope this helps!

API Upload files with metadata

I'm looking for some guidance here.
Scenario:
I have a Post model with a polymorphic relation to a Comment model. Whenever I want to create a new comment for a given post I have the following endpoint:
$router->post('/posts/{post}/comments', 'PostsCommentsController#store');
So far so good. Now I want to add an Attachment model which will also be a polymorphic relation since I may need to add attachments to more things other than comments (ex: messages, etc).
My first idea was doing something in the lines of:
$router->post('/posts/{post}/comments/attachments', 'PostsCommentsAttachmentsController#store');
So the comment will belong to a post and will have an attachment.
This feels a bit "dirty" to me (especially the controller name) and the need of having 3 nested resources (maybe I'm just thinking too much).
Hope I was clear enough explaining my problem :)
Have anyone faced something like this before? How did you guys solve it?
Other approaches? Am I thinking completely wrong?
Open to ideas and suggestions :D
Thank you all.
I'd prefer Single Responsibility for each Controllers or route. So it's pretty clear what their actually do and handle. Let me give you example:
- Post
/posts -> list all post
/posts/{id} -> get specific post
/posts/{id}/comments -> get comments of the post
- Comment
/comments/{id} -> get specific comment
/comments/{id}/attacments -> get attacments of a comment
- Attachment
/attachment/{id} -> get specific attachment
For Controller name, just keep it simple. Just usePostController, CommentController and AttachmentController. It's quite clear I think.
After more researching, I actually realized that what I wanted to do was basically a file upload with metadata.
Came across this excellent post: HTTP/REST API File Uploads that explains it
PS: Thank you Dharma for the help and time.

Retrieve comments and replies with Koala gem

maybe this is stupid question, but how to retrieve comments and their replies (last 50) from Facebook profile page?
For example: api.get_connections("depechemode","posts") (or feed) give me only comments. Do I really have to create another request for every comment to get its replies? Is there better way to obtain all responses (comments + replies) from posts?
I tried FQL with "googled" examples, but without success...
UPDATE: I can get comments+replies from post with api.get_connections(post_id,"comments", :filter="stream") but is there any other option? It will be nice to get posts+comments+replies with one request...
I'll answer to myself:
graph.get_connections("askdotcom", "posts", :fields=>"message,id,created_time,comments.fields(comments.fields(from,message),message,from),from")
Just had to play with Graph API Explorer

Aliasing ID parameter in URL as string in ASP.NET MVC 4

What i'm trying to do is to rewrite URLs to make them more SEO friendly but i still want to pass a parameter as an int ID.
For example, a URL pointing to a news article might look like this:
"www.domain.com/category-id/article-id" or "domain.com/5/3"
What i want to do is to rewrite the URL everywhere so that the title of the category and the title of the article are written into the URL so it becomes f.x. "domain.com/politics/some-title" but i still want to pass the ID of the article as an argument to the controller action. This is less important for the category but it's something i want to do with the article-id since it's unique but the title might not be.
I have checked out Attribute Routing and looked through some Routing guides and questions but haven't found anything that lets me implement this functionality. I've just started using ASP.NET MVC so i haven't been able to look into anything too advanced.
Thanks in advance.
I would advice to make the article title unique and from the controller action you have to get the article based on the title.
I see you are trying to group the articles based on category. When I initially created my blog I thought the same-thing but soon realized it's not a flexible approach because of couple of reasons.
Say you wrote one article with name some-title and dropped it under a category say politics and so the url will be domain.com/politics/some-title but at a later point of time you thought to move the article to another category say 'international-politics' therefore your url now has to be changed to domain.com/international-politics/some-title and you break the old url and whoever has bookmarked that link will now receive 404. A better way would be organize the urls based on the posted date and that's not going to change something like http://domain.com/archive/yyyy/mm/dd/unique_title
Sometimes you want to label an article with more than one category and at that time a tag based approach will become a better choice compared to category based approach.
Quick and dirty solutions:
1) domain.com/categoryName/articleID/articleName/
2) domain.com/date/categoryName/articleName (date should help make articleName unique)
3) domain.com/categoryName/articleName?id=xxx
Nothing fancy, but those approaches will work.

Form from another model in a view

So I'm trying to extend the Blog tutorial adding some comments:
Post hasMany Comments
I want to display the add comment form in the same view as the 'post view'. Thing is I don't know the best way to get this approach. I thought about three ways:
Creating a function in Comments Controller to handle the data.
Creating a function in Post Controller to handle the data.
Deal with the data in the same function that deals with the post views.
The main problem with the two first 'solutions' is that the validation errors doesn't show up in the form unless I do some messy hacking of saving the invalidated field in a session variable and then parsing the variable on the beforeFilter callback, like this:
function beforeFilter () {
if ($this->Session->check('comment_error')) {
$this->Post->Comment->validationErrors = $this->Session->read('comment_error');
$this->Session->delete('comment_error');
}
}
What I basically do is adapt the invalidated fields to the actual view and allow it to show properly. This works really well, but it seems so ugly to me. What would be the best approach?
Another related question: should a controller reflect a view? I mean on that example, I thought about only having a Comment Model and dealing with all the data in the controller where's the form to add a comment (even though it's in the Post Controller).
Sounds like you're looking for the Mutlivalidatable behaviour: http://bakery.cakephp.org/articles/dardosordi/2008/07/29/multivalidatablebehavior-using-many-validation-rulesets-per-model
This allows you to define more than 1 validation ruleset per model. Use your controller to determine which one to apply upon posting something.
P.S. I have only ever used this on a Cake 1.3 project, not sure if it'll work on 2.0.
I see it this way:
Under every post there is an input box "Add comment" with a button to submit.
After submitting some text a form redirects to comments_controller where the comment is saved with this post_id, body, author, date etc.
After the comment is saved and all the logic is done it takes you back to the post.
Under each post there are all related comments displayed (having the same post_id sorted by date or whatever).

Resources